Skip to contentSkip to conversation

mei: Drop unnecessary NULL check after container_of

PATCH In review Guenter Roeck 2 participants 2 messages May 11, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mei: Drop unnecessary NULL check after container_of

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

---
 drivers/misc/mei/main.c | 2 --
 1 file changed, 2 deletions(-)
drivers/misc/mei/main.c +0 -2
index 28937b6e7e0c..9001c45f6fc4 100644
@@ -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);
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 26 lines

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

Quoted 1 line
Quoted 19 lines
---
 drivers/misc/mei/main.c | 2 --
 1 file changed, 2 deletions(-)
drivers/misc/mei/main.c index renamed from drivers/misc/mei/main.c +0 -0

28937b6e7e0c..9001c45f6fc4 100644

drivers/misc/mei/main.c +0 -3
@@ -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