Re: [PATCH 1/2] i2c: Added feature to get bus number from alias

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

 



Hi Alexander,

On Fri, Jul 14, 2023 at 08:15:08AM +0300, Alexander Shiyan wrote:
> For the correct assignment of the I2C bus number, let's use an alias
> from the devicetree.
> 
> Signed-off-by: Alexander Shiyan <eagle.alexander923@xxxxxxxxx>
> ---
>  drivers/i2c/i2c.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index 300365bd1f..df3b968a4b 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -701,17 +701,21 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
>  	int ret;
>  
>  	if (adapter->nr < 0) {
> -		int nr;
> +		if (!adapter->dev.of_node) {
> +			int nr = adapter->dev.id;

nr is initialized but the initialization value is never used.

>  
> -		for (nr = 0;; nr++)
> -			if (!i2c_get_adapter(nr))
> -				break;
> -		adapter->nr = nr;
> -	} else {
> -		if (i2c_get_adapter(adapter->nr))
> -			return -EBUSY;
> +			for (nr = 0;; nr++)
> +				if (!i2c_get_adapter(nr))
> +					break;
> +			adapter->nr = nr;
> +		} else
> +			adapter->nr =
> +				of_alias_get_id(adapter->dev.of_node, "i2c");

of_alias_get_id() can return a negative error code when no alias exists.
You should catch this and either error out or provide a fallback.

Sascha

>  
> +	if (i2c_get_adapter(adapter->nr))
> +		return -EBUSY;
> +
>  	adapter->dev.id = adapter->nr;
>  	dev_set_name(&adapter->dev, "i2c");
>  
> -- 
> 2.38.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