linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mei: Drop unnecessary NULL check after container_of
@ 2021-05-11  4:55 Guenter Roeck
  2021-05-11  5:16 ` Winkler, Tomas
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2021-05-11  4:55 UTC (permalink / raw)
  To: Tomas Winkler
  Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel, Guenter Roeck

The result of container_of() operations is never NULL unless the embedded
element is the first element of the data structure, which is not the case
here. The NULL check 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
...+>

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/misc/mei/main.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 28937b6e7e0c..9001c45f6fc4 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -50,8 +50,6 @@ static int mei_open(struct inode *inode, struct file *file)
 	int err;
 
 	dev = container_of(inode->i_cdev, struct mei_device, cdev);
-	if (!dev)
-		return -ENODEV;
 
 	mutex_lock(&dev->device_lock);
 
-- 
2.25.1


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

* RE: [PATCH] mei: Drop unnecessary NULL check after container_of
  2021-05-11  4:55 [PATCH] mei: Drop unnecessary NULL check after container_of Guenter Roeck
@ 2021-05-11  5:16 ` Winkler, Tomas
  0 siblings, 0 replies; 2+ messages in thread
From: Winkler, Tomas @ 2021-05-11  5:16 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel



> 
> The result of container_of() operations is never NULL unless the embedded
> element is the first element of the data structure, which is not the case here.
> The NULL check 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
> ...+>
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Tomas Winkler <tomas.winkler@intel.com>
> ---
>  drivers/misc/mei/main.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c index
> 28937b6e7e0c..9001c45f6fc4 100644
> --- a/drivers/misc/mei/main.c
> +++ b/drivers/misc/mei/main.c
> @@ -50,8 +50,6 @@ static int mei_open(struct inode *inode, struct file *file)
>  	int err;
> 
>  	dev = container_of(inode->i_cdev, struct mei_device, cdev);
> -	if (!dev)
> -		return -ENODEV;
> 
>  	mutex_lock(&dev->device_lock);
> 
> --
> 2.25.1


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

end of thread, other threads:[~2021-05-11  5:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11  4:55 [PATCH] mei: Drop unnecessary NULL check after container_of Guenter Roeck
2021-05-11  5:16 ` Winkler, Tomas

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).