public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] i2c: rtl9300: two cleanups
@ 2025-12-17  6:30 Rosen Penev
  2025-12-17  6:30 ` [PATCH 1/2] i2c: rtl9300: remove const cast Rosen Penev
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Rosen Penev @ 2025-12-17  6:30 UTC (permalink / raw)
  To: linux-i2c; +Cc: Chris Packham, Andi Shyti, open list

const fix and fwnode removal.

Rosen Penev (2):
  i2c: rtl9300: remove const cast
  i2c: rtl9300: use of instead of fwnode

 drivers/i2c/busses/i2c-rtl9300.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

--
2.52.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] i2c: rtl9300: remove const cast
  2025-12-17  6:30 [PATCH 0/2] i2c: rtl9300: two cleanups Rosen Penev
@ 2025-12-17  6:30 ` Rosen Penev
  2025-12-17 19:39   ` Chris Packham
  2025-12-17  6:30 ` [PATCH 2/2] i2c: rtl9300: use of instead of fwnode Rosen Penev
  2026-01-15 17:34 ` [PATCH 0/2] i2c: rtl9300: two cleanups Andi Shyti
  2 siblings, 1 reply; 7+ messages in thread
From: Rosen Penev @ 2025-12-17  6:30 UTC (permalink / raw)
  To: linux-i2c; +Cc: Chris Packham, Andi Shyti, open list

These casts are used to remove const for no good reason. Fix the types
instead.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/i2c/busses/i2c-rtl9300.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c
index 4723e48cfe18..f2aa341a7cdd 100644
--- a/drivers/i2c/busses/i2c-rtl9300.c
+++ b/drivers/i2c/busses/i2c-rtl9300.c
@@ -129,7 +129,7 @@ static int rtl9310_i2c_select_scl(struct rtl9300_i2c *i2c, u8 scl)
 
 static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_chan *chan)
 {
-	struct rtl9300_i2c_drv_data *drv_data;
+	const struct rtl9300_i2c_drv_data *drv_data;
 	int ret;
 
 	if (i2c->sda_num == chan->sda_num)
@@ -139,7 +139,7 @@ static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_c
 	if (ret)
 		return ret;
 
-	drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
+	drv_data = device_get_match_data(i2c->dev);
 	ret = drv_data->select_scl(i2c, i2c->scl_num);
 	if (ret)
 		return ret;
@@ -372,7 +372,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct rtl9300_i2c *i2c;
 	struct fwnode_handle *child;
-	struct rtl9300_i2c_drv_data *drv_data;
+	const struct rtl9300_i2c_drv_data *drv_data;
 	struct reg_field fields[F_NUM_FIELDS];
 	u32 clock_freq, scl_num, sda_num;
 	int ret, i = 0;
@@ -399,7 +399,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, i2c);
 
-	drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
+	drv_data = device_get_match_data(i2c->dev);
 	if (device_get_child_node_count(dev) > drv_data->max_nchan)
 		return dev_err_probe(dev, -EINVAL, "Too many channels\n");
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] i2c: rtl9300: use of instead of fwnode
  2025-12-17  6:30 [PATCH 0/2] i2c: rtl9300: two cleanups Rosen Penev
  2025-12-17  6:30 ` [PATCH 1/2] i2c: rtl9300: remove const cast Rosen Penev
@ 2025-12-17  6:30 ` Rosen Penev
  2025-12-17 19:43   ` Chris Packham
  2026-01-15 17:34 ` [PATCH 0/2] i2c: rtl9300: two cleanups Andi Shyti
  2 siblings, 1 reply; 7+ messages in thread
From: Rosen Penev @ 2025-12-17  6:30 UTC (permalink / raw)
  To: linux-i2c; +Cc: Chris Packham, Andi Shyti, open list

Avoids having to use to_of_node and just assign directly. This is an OF
only driver anyway.

Use _scoped for the for each loop to avoid refcount leaks.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/i2c/busses/i2c-rtl9300.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c
index f2aa341a7cdd..672cb978066d 100644
--- a/drivers/i2c/busses/i2c-rtl9300.c
+++ b/drivers/i2c/busses/i2c-rtl9300.c
@@ -371,7 +371,6 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct rtl9300_i2c *i2c;
-	struct fwnode_handle *child;
 	const struct rtl9300_i2c_drv_data *drv_data;
 	struct reg_field fields[F_NUM_FIELDS];
 	u32 clock_freq, scl_num, sda_num;
@@ -415,15 +414,15 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 		return ret;
 
 	i = 0;
-	device_for_each_child_node(dev, child) {
+	for_each_child_of_node_scoped(dev->of_node, child) {
 		struct rtl9300_i2c_chan *chan = &i2c->chans[i];
 		struct i2c_adapter *adap = &chan->adap;
 
-		ret = fwnode_property_read_u32(child, "reg", &sda_num);
+		ret = of_property_read_u32(child, "reg", &sda_num);
 		if (ret)
 			return ret;
 
-		ret = fwnode_property_read_u32(child, "clock-frequency", &clock_freq);
+		ret = of_property_read_u32(child, "clock-frequency", &clock_freq);
 		if (ret)
 			clock_freq = I2C_MAX_STANDARD_MODE_FREQ;
 
@@ -449,7 +448,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 		adap->retries = 3;
 		adap->dev.parent = dev;
 		i2c_set_adapdata(adap, chan);
-		adap->dev.of_node = to_of_node(child);
+		adap->dev.of_node = child;
 		snprintf(adap->name, sizeof(adap->name), "%s SDA%d\n", dev_name(dev), sda_num);
 		i++;
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] i2c: rtl9300: remove const cast
  2025-12-17  6:30 ` [PATCH 1/2] i2c: rtl9300: remove const cast Rosen Penev
@ 2025-12-17 19:39   ` Chris Packham
  0 siblings, 0 replies; 7+ messages in thread
From: Chris Packham @ 2025-12-17 19:39 UTC (permalink / raw)
  To: Rosen Penev, linux-i2c@vger.kernel.org; +Cc: Andi Shyti, open list

Hi Rosen,

On 17/12/2025 19:30, Rosen Penev wrote:
> These casts are used to remove const for no good reason. Fix the types
> instead.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

> ---
>   drivers/i2c/busses/i2c-rtl9300.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c
> index 4723e48cfe18..f2aa341a7cdd 100644
> --- a/drivers/i2c/busses/i2c-rtl9300.c
> +++ b/drivers/i2c/busses/i2c-rtl9300.c
> @@ -129,7 +129,7 @@ static int rtl9310_i2c_select_scl(struct rtl9300_i2c *i2c, u8 scl)
>   
>   static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_chan *chan)
>   {
> -	struct rtl9300_i2c_drv_data *drv_data;
> +	const struct rtl9300_i2c_drv_data *drv_data;
>   	int ret;
>   
>   	if (i2c->sda_num == chan->sda_num)
> @@ -139,7 +139,7 @@ static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_c
>   	if (ret)
>   		return ret;
>   
> -	drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
> +	drv_data = device_get_match_data(i2c->dev);
>   	ret = drv_data->select_scl(i2c, i2c->scl_num);
>   	if (ret)
>   		return ret;
> @@ -372,7 +372,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
>   	struct device *dev = &pdev->dev;
>   	struct rtl9300_i2c *i2c;
>   	struct fwnode_handle *child;
> -	struct rtl9300_i2c_drv_data *drv_data;
> +	const struct rtl9300_i2c_drv_data *drv_data;
>   	struct reg_field fields[F_NUM_FIELDS];
>   	u32 clock_freq, scl_num, sda_num;
>   	int ret, i = 0;
> @@ -399,7 +399,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
>   
>   	platform_set_drvdata(pdev, i2c);
>   
> -	drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
> +	drv_data = device_get_match_data(i2c->dev);
>   	if (device_get_child_node_count(dev) > drv_data->max_nchan)
>   		return dev_err_probe(dev, -EINVAL, "Too many channels\n");
>   

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] i2c: rtl9300: use of instead of fwnode
  2025-12-17  6:30 ` [PATCH 2/2] i2c: rtl9300: use of instead of fwnode Rosen Penev
@ 2025-12-17 19:43   ` Chris Packham
  2025-12-17 20:11     ` Rosen Penev
  0 siblings, 1 reply; 7+ messages in thread
From: Chris Packham @ 2025-12-17 19:43 UTC (permalink / raw)
  To: Rosen Penev, linux-i2c@vger.kernel.org; +Cc: Andi Shyti, open list

Hi Rosen,

On 17/12/2025 19:30, Rosen Penev wrote:
> Avoids having to use to_of_node and just assign directly. This is an OF
> only driver anyway.
>
> Use _scoped for the for each loop to avoid refcount leaks.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

I thought the trend was to move to the more generic device properties 
rather than using of_ specific APIs which is why I wrote the driver 
using them. I agree that this driver is unlikely to be used on any 
platform that doesn't use a device tree so if Andi is happy with this 
I'm fine with the change.

Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

> ---
>   drivers/i2c/busses/i2c-rtl9300.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c
> index f2aa341a7cdd..672cb978066d 100644
> --- a/drivers/i2c/busses/i2c-rtl9300.c
> +++ b/drivers/i2c/busses/i2c-rtl9300.c
> @@ -371,7 +371,6 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
>   {
>   	struct device *dev = &pdev->dev;
>   	struct rtl9300_i2c *i2c;
> -	struct fwnode_handle *child;
>   	const struct rtl9300_i2c_drv_data *drv_data;
>   	struct reg_field fields[F_NUM_FIELDS];
>   	u32 clock_freq, scl_num, sda_num;
> @@ -415,15 +414,15 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
>   		return ret;
>   
>   	i = 0;
> -	device_for_each_child_node(dev, child) {
> +	for_each_child_of_node_scoped(dev->of_node, child) {
>   		struct rtl9300_i2c_chan *chan = &i2c->chans[i];
>   		struct i2c_adapter *adap = &chan->adap;
>   
> -		ret = fwnode_property_read_u32(child, "reg", &sda_num);
> +		ret = of_property_read_u32(child, "reg", &sda_num);
>   		if (ret)
>   			return ret;
>   
> -		ret = fwnode_property_read_u32(child, "clock-frequency", &clock_freq);
> +		ret = of_property_read_u32(child, "clock-frequency", &clock_freq);
>   		if (ret)
>   			clock_freq = I2C_MAX_STANDARD_MODE_FREQ;
>   
> @@ -449,7 +448,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
>   		adap->retries = 3;
>   		adap->dev.parent = dev;
>   		i2c_set_adapdata(adap, chan);
> -		adap->dev.of_node = to_of_node(child);
> +		adap->dev.of_node = child;
>   		snprintf(adap->name, sizeof(adap->name), "%s SDA%d\n", dev_name(dev), sda_num);
>   		i++;
>   

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] i2c: rtl9300: use of instead of fwnode
  2025-12-17 19:43   ` Chris Packham
@ 2025-12-17 20:11     ` Rosen Penev
  0 siblings, 0 replies; 7+ messages in thread
From: Rosen Penev @ 2025-12-17 20:11 UTC (permalink / raw)
  To: Chris Packham; +Cc: linux-i2c@vger.kernel.org, Andi Shyti, open list

On Wed, Dec 17, 2025 at 11:43 AM Chris Packham
<Chris.Packham@alliedtelesis.co.nz> wrote:
>
> Hi Rosen,
>
> On 17/12/2025 19:30, Rosen Penev wrote:
> > Avoids having to use to_of_node and just assign directly. This is an OF
> > only driver anyway.
> >
> > Use _scoped for the for each loop to avoid refcount leaks.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
>
> I thought the trend was to move to the more generic device properties
> rather than using of_ specific APIs which is why I wrote the driver
> using them. I agree that this driver is unlikely to be used on any
> platform that doesn't use a device tree so if Andi is happy with this
> I'm fine with the change.
I've gotten the opposite advice on netdev before.
>
> Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>
> > ---
> >   drivers/i2c/busses/i2c-rtl9300.c | 9 ++++-----
> >   1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c
> > index f2aa341a7cdd..672cb978066d 100644
> > --- a/drivers/i2c/busses/i2c-rtl9300.c
> > +++ b/drivers/i2c/busses/i2c-rtl9300.c
> > @@ -371,7 +371,6 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
> >   {
> >       struct device *dev = &pdev->dev;
> >       struct rtl9300_i2c *i2c;
> > -     struct fwnode_handle *child;
> >       const struct rtl9300_i2c_drv_data *drv_data;
> >       struct reg_field fields[F_NUM_FIELDS];
> >       u32 clock_freq, scl_num, sda_num;
> > @@ -415,15 +414,15 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
> >               return ret;
> >
> >       i = 0;
> > -     device_for_each_child_node(dev, child) {
> > +     for_each_child_of_node_scoped(dev->of_node, child) {
> >               struct rtl9300_i2c_chan *chan = &i2c->chans[i];
> >               struct i2c_adapter *adap = &chan->adap;
> >
> > -             ret = fwnode_property_read_u32(child, "reg", &sda_num);
> > +             ret = of_property_read_u32(child, "reg", &sda_num);
> >               if (ret)
> >                       return ret;
> >
> > -             ret = fwnode_property_read_u32(child, "clock-frequency", &clock_freq);
> > +             ret = of_property_read_u32(child, "clock-frequency", &clock_freq);
> >               if (ret)
> >                       clock_freq = I2C_MAX_STANDARD_MODE_FREQ;
> >
> > @@ -449,7 +448,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
> >               adap->retries = 3;
> >               adap->dev.parent = dev;
> >               i2c_set_adapdata(adap, chan);
> > -             adap->dev.of_node = to_of_node(child);
> > +             adap->dev.of_node = child;
> >               snprintf(adap->name, sizeof(adap->name), "%s SDA%d\n", dev_name(dev), sda_num);
> >               i++;
> >

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] i2c: rtl9300: two cleanups
  2025-12-17  6:30 [PATCH 0/2] i2c: rtl9300: two cleanups Rosen Penev
  2025-12-17  6:30 ` [PATCH 1/2] i2c: rtl9300: remove const cast Rosen Penev
  2025-12-17  6:30 ` [PATCH 2/2] i2c: rtl9300: use of instead of fwnode Rosen Penev
@ 2026-01-15 17:34 ` Andi Shyti
  2 siblings, 0 replies; 7+ messages in thread
From: Andi Shyti @ 2026-01-15 17:34 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-i2c, Chris Packham, open list

Hi Rosen,

On Tue, Dec 16, 2025 at 10:30:25PM -0800, Rosen Penev wrote:
> Rosen Penev (2):
>   i2c: rtl9300: remove const cast
>   i2c: rtl9300: use of instead of fwnode

merged to i2c/i2c-host.

Thanks,
Andi

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-01-15 17:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-17  6:30 [PATCH 0/2] i2c: rtl9300: two cleanups Rosen Penev
2025-12-17  6:30 ` [PATCH 1/2] i2c: rtl9300: remove const cast Rosen Penev
2025-12-17 19:39   ` Chris Packham
2025-12-17  6:30 ` [PATCH 2/2] i2c: rtl9300: use of instead of fwnode Rosen Penev
2025-12-17 19:43   ` Chris Packham
2025-12-17 20:11     ` Rosen Penev
2026-01-15 17:34 ` [PATCH 0/2] i2c: rtl9300: two cleanups Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox