diff mbox series

[v2,1/2] mei: bus: simplify mei_cl_device_remove()

Message ID 20210208073705.428185-2-uwe@kleine-koenig.org (mailing list archive)
State Not Applicable
Headers show
Series mei: bus: Some cleanups | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Uwe Kleine-König Feb. 8, 2021, 7:37 a.m. UTC
The driver core only calls a bus' remove function when there is actually
a driver and a device. So drop the needless check and assign cldrv earlier.

(Side note: The check for cldev being non-NULL is broken anyhow, because
to_mei_cl_device() is a wrapper around container_of() for a member that is
not the first one. So cldev only can become NULL if dev is (void *)0xc
(for archs with 32 bit pointers) or (void *)0x18 (for archs with 64 bit
pointers).)

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
---
 drivers/misc/mei/bus.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Greg KH Feb. 8, 2021, 8:22 a.m. UTC | #1
On Mon, Feb 08, 2021 at 08:37:04AM +0100, Uwe Kleine-König wrote:
> The driver core only calls a bus' remove function when there is actually
> a driver and a device. So drop the needless check and assign cldrv earlier.
> 
> (Side note: The check for cldev being non-NULL is broken anyhow, because
> to_mei_cl_device() is a wrapper around container_of() for a member that is
> not the first one. So cldev only can become NULL if dev is (void *)0xc
> (for archs with 32 bit pointers) or (void *)0x18 (for archs with 64 bit
> pointers).)
> 
> Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
> ---
>  drivers/misc/mei/bus.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
> index 2907db260fba..50d617e7467e 100644
> --- a/drivers/misc/mei/bus.c
> +++ b/drivers/misc/mei/bus.c
> @@ -878,13 +878,9 @@ static int mei_cl_device_probe(struct device *dev)
>  static int mei_cl_device_remove(struct device *dev)
>  {
>  	struct mei_cl_device *cldev = to_mei_cl_device(dev);
> -	struct mei_cl_driver *cldrv;
> +	struct mei_cl_driver *cldrv = to_mei_cl_driver(dev->driver);
>  	int ret = 0;
>  
> -	if (!cldev || !dev->driver)

Yes, anyone checking that the results of a container_of() wrapper can be
NULL is not checking anything at all :)

thanks for the cleanups, I'll go queue them up.

greg k-h
diff mbox series

Patch

diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index 2907db260fba..50d617e7467e 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -878,13 +878,9 @@  static int mei_cl_device_probe(struct device *dev)
 static int mei_cl_device_remove(struct device *dev)
 {
 	struct mei_cl_device *cldev = to_mei_cl_device(dev);
-	struct mei_cl_driver *cldrv;
+	struct mei_cl_driver *cldrv = to_mei_cl_driver(dev->driver);
 	int ret = 0;
 
-	if (!cldev || !dev->driver)
-		return 0;
-
-	cldrv = to_mei_cl_driver(dev->driver);
 	if (cldrv->remove)
 		ret = cldrv->remove(cldev);