linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/msm/dp: Drop unnecessary NULL checks after container_of
@ 2021-05-25  3:20 Guenter Roeck
  2021-05-25 18:34 ` [Freedreno] " abhinavk
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2021-05-25  3:20 UTC (permalink / raw)
  To: Rob Clark
  Cc: Sean Paul, David Airlie, Daniel Vetter, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, Guenter Roeck

The result of container_of() operations is never NULL unless the embedded
element is the first element of the structure. This is not the case here.
The NULL check on the result of container_of() is therefore unnecessary
and misleading. Remove it.

This change was made automatically with the following Coccinelle script.

@@
type t;
identifier v;
statement s;
@@

<+...
(
  t v = container_of(...);
|
  v = container_of(...);
)
  ...
  when != v
- if (\( !v \| v == NULL \) ) s
...+>

While at it, remove unused but assigned variable hpd in
dp_display_usbpd_attention_cb().

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/gpu/drm/msm/dp/dp_display.c | 25 -------------------------
 1 file changed, 25 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index 1784e119269b..a74e7ef96fcf 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -208,10 +208,6 @@ static int dp_display_bind(struct device *dev, struct device *master,
 
 	dp = container_of(g_dp_display,
 			struct dp_display_private, dp_display);
-	if (!dp) {
-		DRM_ERROR("DP driver bind failed. Invalid driver data\n");
-		return -EINVAL;
-	}
 
 	dp->dp_display.drm_dev = drm;
 	priv = drm->dev_private;
@@ -252,10 +248,6 @@ static void dp_display_unbind(struct device *dev, struct device *master,
 
 	dp = container_of(g_dp_display,
 			struct dp_display_private, dp_display);
-	if (!dp) {
-		DRM_ERROR("Invalid DP driver data\n");
-		return;
-	}
 
 	dp_power_client_deinit(dp->power);
 	dp_aux_unregister(dp->aux);
@@ -406,11 +398,6 @@ static int dp_display_usbpd_configure_cb(struct device *dev)
 
 	dp = container_of(g_dp_display,
 			struct dp_display_private, dp_display);
-	if (!dp) {
-		DRM_ERROR("no driver data found\n");
-		rc = -ENODEV;
-		goto end;
-	}
 
 	dp_display_host_init(dp, false);
 
@@ -437,11 +424,6 @@ static int dp_display_usbpd_disconnect_cb(struct device *dev)
 
 	dp = container_of(g_dp_display,
 			struct dp_display_private, dp_display);
-	if (!dp) {
-		DRM_ERROR("no driver data found\n");
-		rc = -ENODEV;
-		return rc;
-	}
 
 	dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
 
@@ -502,7 +484,6 @@ static int dp_display_usbpd_attention_cb(struct device *dev)
 	int rc = 0;
 	u32 sink_request;
 	struct dp_display_private *dp;
-	struct dp_usbpd *hpd;
 
 	if (!dev) {
 		DRM_ERROR("invalid dev\n");
@@ -511,12 +492,6 @@ static int dp_display_usbpd_attention_cb(struct device *dev)
 
 	dp = container_of(g_dp_display,
 			struct dp_display_private, dp_display);
-	if (!dp) {
-		DRM_ERROR("no driver data found\n");
-		return -ENODEV;
-	}
-
-	hpd = dp->usbpd;
 
 	/* check for any test request issued by sink */
 	rc = dp_link_process_request(dp->link);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Freedreno] [PATCH] drm/msm/dp: Drop unnecessary NULL checks after container_of
  2021-05-25  3:20 [PATCH] drm/msm/dp: Drop unnecessary NULL checks after container_of Guenter Roeck
@ 2021-05-25 18:34 ` abhinavk
  0 siblings, 0 replies; 2+ messages in thread
From: abhinavk @ 2021-05-25 18:34 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Rob Clark, Sean Paul, David Airlie, linux-arm-msm, linux-kernel,
	dri-devel, Daniel Vetter, freedreno

On 2021-05-24 20:20, Guenter Roeck wrote:
> The result of container_of() operations is never NULL unless the 
> embedded
> element is the first element of the structure. This is not the case 
> here.
> The NULL check on the result of container_of() is therefore unnecessary
> and misleading. Remove it.
> 
> This change was made automatically with the following Coccinelle 
> script.
> 
> @@
> type t;
> identifier v;
> statement s;
> @@
> 
> <+...
> (
>   t v = container_of(...);
> |
>   v = container_of(...);
> )
>   ...
>   when != v
> - if (\( !v \| v == NULL \) ) s
> ...+>
> 
> While at it, remove unused but assigned variable hpd in
> dp_display_usbpd_attention_cb().
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Abhinav Kumar <abhinavk@codeaurora.org>
> ---
>  drivers/gpu/drm/msm/dp/dp_display.c | 25 -------------------------
>  1 file changed, 25 deletions(-)
> 
> diff --git a/drivers/gpu/drm/msm/dp/dp_display.c
> b/drivers/gpu/drm/msm/dp/dp_display.c
> index 1784e119269b..a74e7ef96fcf 100644
> --- a/drivers/gpu/drm/msm/dp/dp_display.c
> +++ b/drivers/gpu/drm/msm/dp/dp_display.c
> @@ -208,10 +208,6 @@ static int dp_display_bind(struct device *dev,
> struct device *master,
> 
>  	dp = container_of(g_dp_display,
>  			struct dp_display_private, dp_display);
> -	if (!dp) {
> -		DRM_ERROR("DP driver bind failed. Invalid driver data\n");
> -		return -EINVAL;
> -	}
> 
>  	dp->dp_display.drm_dev = drm;
>  	priv = drm->dev_private;
> @@ -252,10 +248,6 @@ static void dp_display_unbind(struct device *dev,
> struct device *master,
> 
>  	dp = container_of(g_dp_display,
>  			struct dp_display_private, dp_display);
> -	if (!dp) {
> -		DRM_ERROR("Invalid DP driver data\n");
> -		return;
> -	}
> 
>  	dp_power_client_deinit(dp->power);
>  	dp_aux_unregister(dp->aux);
> @@ -406,11 +398,6 @@ static int dp_display_usbpd_configure_cb(struct
> device *dev)
> 
>  	dp = container_of(g_dp_display,
>  			struct dp_display_private, dp_display);
> -	if (!dp) {
> -		DRM_ERROR("no driver data found\n");
> -		rc = -ENODEV;
> -		goto end;
> -	}
> 
>  	dp_display_host_init(dp, false);
> 
> @@ -437,11 +424,6 @@ static int dp_display_usbpd_disconnect_cb(struct
> device *dev)
> 
>  	dp = container_of(g_dp_display,
>  			struct dp_display_private, dp_display);
> -	if (!dp) {
> -		DRM_ERROR("no driver data found\n");
> -		rc = -ENODEV;
> -		return rc;
> -	}
> 
>  	dp_add_event(dp, EV_USER_NOTIFICATION, false, 0);
> 
> @@ -502,7 +484,6 @@ static int dp_display_usbpd_attention_cb(struct 
> device *dev)
>  	int rc = 0;
>  	u32 sink_request;
>  	struct dp_display_private *dp;
> -	struct dp_usbpd *hpd;
> 
>  	if (!dev) {
>  		DRM_ERROR("invalid dev\n");
> @@ -511,12 +492,6 @@ static int dp_display_usbpd_attention_cb(struct
> device *dev)
> 
>  	dp = container_of(g_dp_display,
>  			struct dp_display_private, dp_display);
> -	if (!dp) {
> -		DRM_ERROR("no driver data found\n");
> -		return -ENODEV;
> -	}
> -
> -	hpd = dp->usbpd;
> 
>  	/* check for any test request issued by sink */
>  	rc = dp_link_process_request(dp->link);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-25 18:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25  3:20 [PATCH] drm/msm/dp: Drop unnecessary NULL checks after container_of Guenter Roeck
2021-05-25 18:34 ` [Freedreno] " abhinavk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).