mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Alexander Shiyan <eagle.alexander923@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] i2c: Added feature to get bus number from alias
Date: Wed, 26 Jul 2023 13:55:46 +0200	[thread overview]
Message-ID: <20230726115546.GN18491@pengutronix.de> (raw)
In-Reply-To: <20230714051510.2304-2-eagle.alexander923@gmail.com>

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@gmail.com>
> ---
>  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 |



  reply	other threads:[~2023-07-26 11:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-14  5:15 [PATCH] .gitignore: Add generated scripts/rkimage to .gitignore Alexander Shiyan
2023-07-14  5:15 ` [PATCH 1/2] i2c: Added feature to get bus number from alias Alexander Shiyan
2023-07-26 11:55   ` Sascha Hauer [this message]
2023-07-14  5:15 ` [PATCH] mfd: rk808: Add missing RK809 chip ID to poweroff handler Alexander Shiyan
2023-07-14  5:15 ` [PATCH 2/2] i2c: rockchip: Get I2C bus number from devicetree alias Alexander Shiyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230726115546.GN18491@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=eagle.alexander923@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox