mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Ahmad Byagowi <ahmadexp@gmail.com>
Cc: Andi Shyti <andi.shyti@kernel.org>,
	Peter Rosin <peda@lysator.liu.se>,
	Andy Shevchenko <andy@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 1/2] i2c: mux: Factor out channel node lookup
Date: Tue, 1 Sep 2026 11:50:17 +0300	[thread overview]
Message-ID: <apaRyWDhpZ87sG4W@ashevche-desk.local> (raw)
In-Reply-To: <6ff921823286515e75b62493e748ed08f4816358.1788181174.git.ahmadexp@gmail.com>

On Mon, Aug 31, 2026 at 10:22:06AM -0700, Ahmad Byagowi wrote:
> Move the existing Device Tree channel-node lookup into a helper in
> preparation for using generic firmware-node operations.
> 
> This is a pure refactoring with no functional change.

...

> +static struct device_node *
> +i2c_mux_get_channel_node(struct i2c_mux_core *muxc, u32 chan_id)
> +{
> +	struct device_node *dev_node = muxc->dev->of_node;

It's better for maintenance to split assignment (due to validation below).

	struct device_node *dev_node;

> +	struct device_node *mux_node, *child;
> +	u32 reg;
> +	int ret;

// also use getter
	dev_node = dev_of_node(dev);

> +	if (!dev_node)
> +		return NULL;

Looking at the code, it's NULL-aware as far as I can see and this check is just
a shortcut.

> +	if (muxc->arbitrator)
> +		mux_node = of_get_child_by_name(dev_node, "i2c-arb");
> +	else if (muxc->gate)
> +		mux_node = of_get_child_by_name(dev_node, "i2c-gate");
> +	else
> +		mux_node = of_get_child_by_name(dev_node, "i2c-mux");
> +
> +	if (mux_node) {
> +		/* A "reg" property indicates an old-style DT entry */
> +		if (!of_property_read_u32(mux_node, "reg", &reg)) {
> +			of_node_put(mux_node);
> +			mux_node = NULL;
> +		}
> +	}
> +
> +	if (!mux_node)
> +		mux_node = of_node_get(dev_node);
> +	else if (muxc->arbitrator || muxc->gate)
> +		return mux_node;
> +
> +	for_each_child_of_node(mux_node, child) {
> +		ret = of_property_read_u32(child, "reg", &reg);
> +		if (ret)
> +			continue;
> +		if (chan_id == reg)
> +			break;
> +	}
> +
> +	of_node_put(mux_node);
> +	return child;
> +}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-09-01  8:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 17:22 [PATCH v8 0/2] i2c: mux: Propagate firmware nodes to channel adapters Ahmad Byagowi
2026-08-31 17:22 ` [PATCH v8 1/2] i2c: mux: Factor out channel node lookup Ahmad Byagowi
2026-09-01  8:50   ` Andy Shevchenko [this message]
2026-08-31 17:22 ` [PATCH v8 2/2] i2c: mux: Propagate firmware nodes to channel adapters Ahmad Byagowi
2026-09-01  8:54   ` Andy Shevchenko

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=apaRyWDhpZ87sG4W@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=ahmadexp@gmail.com \
    --cc=andi.shyti@kernel.org \
    --cc=andy@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peda@lysator.liu.se \
    /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

all inboxes | Powered by JetHome®