Re: [PATCH 1/2] cdev: simplify loop in cdev_by_device_node

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 03, 2024 at 11:20:34AM +0100, Ahmad Fatoum wrote:
> We don't need to compare the cdev's device node pointer both against NULL
> and against the searched for device node on each iteration.
> 
> Instead, it's sufficient to just compare the device nodes directly.
> To maintain previous behavior, when searching for a NULL device node, we
> shouldn't return the first cdev, but return NULL. Do that via an early
> exit instead of doing it after iterating over all cdevs.
> 
> No functional change.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
> ---
>  fs/devfs-core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> index 244f76f62c52..c79b092a112e 100644
> --- a/fs/devfs-core.c
> +++ b/fs/devfs-core.c
> @@ -87,9 +87,10 @@ struct cdev *cdev_by_device_node(struct device_node *node)
>  {
>  	struct cdev *cdev;
>  
> +	if (!node)
> +		return NULL;
> +
>  	for_each_cdev(cdev) {
> -		if (!cdev->device_node)
> -			continue;
>  		if (cdev->device_node == node)
>  			return cdev_readlink(cdev);
>  	}
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux