diff mbox series

[5/5] coresight: Avoid casting void pointers

Message ID 20200426185805.14923-6-swboyd@chromium.org (mailing list archive)
State New, archived
Headers show
Series coresight: Minor sparse and style fixes | expand

Commit Message

Stephen Boyd April 26, 2020, 6:58 p.m. UTC
We don't need to cast void pointers, such as the amba_id data. Assign to
a local variable to make the code prettier and also return NULL instead
of 0 to make sparse happy.

Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 drivers/hwtracing/coresight/coresight-priv.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Joe Perches April 26, 2020, 8:37 p.m. UTC | #1
On Sun, 2020-04-26 at 11:58 -0700, Stephen Boyd wrote:
> We don't need to cast void pointers, such as the amba_id data. Assign to
> a local variable to make the code prettier and also return NULL instead
> of 0 to make sparse happy.
[]
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
[]
> @@ -206,9 +206,12 @@ cti_remove_assoc_from_csdev(struct coresight_device *csdev) {}
>  /* extract the data value from a UCI structure given amba_id pointer. */
>  static inline void *coresight_get_uci_data(const struct amba_id *id)
>  {
> -	if (id->data)
> -		return ((struct amba_cs_uci_id *)(id->data))->data;
> -	return 0;
> +	struct amba_cs_uci_id *uci_id = id->data;
> +
> +	if (uci_id)
> +		return id->data;

Missing one more level of indirection here yes?

		return uci_id->data;

> +
> +	return NULL;
>  }

And this code would generally be written to return the expected
value at the bottom of the function and any unusual return
early like:

static inline void *coresight_get_uci_data(const struct amba_id *id)
{
	struct amba_cs_uci_id *uci_id = id->data;

	if (!uci_id)
		return NULL;

	return uci_id->data;
}
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index 890f9a5c97c6..09ca9d824cee 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -206,9 +206,12 @@  cti_remove_assoc_from_csdev(struct coresight_device *csdev) {}
 /* extract the data value from a UCI structure given amba_id pointer. */
 static inline void *coresight_get_uci_data(const struct amba_id *id)
 {
-	if (id->data)
-		return ((struct amba_cs_uci_id *)(id->data))->data;
-	return 0;
+	struct amba_cs_uci_id *uci_id = id->data;
+
+	if (uci_id)
+		return id->data;
+
+	return NULL;
 }
 
 void coresight_release_platform_data(struct coresight_platform_data *pdata);