No more special handling needed here, so use dev_err_probe()
to simplify the code.
While at it, use struct dev *dev to replace &pdev->dev to
further simplify the code.
Use the macro definition HZ_PER_KHZ to replace the 1000.
Signed-off-by: Rong Qianfeng <rongqianfeng@vivo.com>
---
drivers/i2c/busses/i2c-jz4780.c | 40 ++++++++++++++++-----------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
index 92cc5b091137..72823a0f39c2 100644
--- a/drivers/i2c/busses/i2c-jz4780.c
+++ b/drivers/i2c/busses/i2c-jz4780.c
@@ -23,6 +23,7 @@
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/time.h>
+#include <linux/units.h>
#define JZ4780_I2C_CTRL 0x00
#define JZ4780_I2C_TAR 0x04
@@ -764,14 +765,15 @@ static int jz4780_i2c_probe(struct platform_device *pdev)
unsigned int clk_freq = 0;
unsigned short tmp;
struct jz4780_i2c *i2c;
+ struct device *dev = &pdev->dev;
- i2c = devm_kzalloc(&pdev->dev, sizeof(struct jz4780_i2c), GFP_KERNEL);
+ i2c = devm_kzalloc(dev, sizeof(struct jz4780_i2c), GFP_KERNEL);
if (!i2c)
return -ENOMEM;
- i2c->cdata = device_get_match_data(&pdev->dev);
+ i2c->cdata = device_get_match_data(dev);
if (!i2c->cdata) {
- dev_err(&pdev->dev, "Error: No device match found\n");
+ dev_err(dev, "Error: No device match found\n");
return -ENODEV;
}
@@ -779,8 +781,8 @@ static int jz4780_i2c_probe(struct platform_device *pdev)
i2c->adap.algo = &jz4780_i2c_algorithm;
i2c->adap.algo_data = i2c;
i2c->adap.retries = 5;
- i2c->adap.dev.parent = &pdev->dev;
- i2c->adap.dev.of_node = pdev->dev.of_node;
+ i2c->adap.dev.parent = dev;
+ i2c->adap.dev.of_node = dev->of_node;
sprintf(i2c->adap.name, "%s", pdev->name);
init_completion(&i2c->trans_waitq);
@@ -792,26 +794,24 @@ static int jz4780_i2c_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, i2c);
- i2c->clk = devm_clk_get_enabled(&pdev->dev, NULL);
+ i2c->clk = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(i2c->clk))
return PTR_ERR(i2c->clk);
- ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
+ ret = of_property_read_u32(dev->of_node, "clock-frequency",
&clk_freq);
- if (ret) {
- dev_err(&pdev->dev, "clock-frequency not specified in DT\n");
- return ret;
- }
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "clock-frequency not specified in DT\n");
+
+ i2c->speed = clk_freq / HZ_PER_KHZ;
+ if (i2c->speed == 0)
+ return dev_err_probe(dev, -EINVAL,
+ "clock-frequency minimum is HZ_PER_KHZ\n");
- i2c->speed = clk_freq / 1000;
- if (i2c->speed == 0) {
- ret = -EINVAL;
- dev_err(&pdev->dev, "clock-frequency minimum is 1000\n");
- return ret;
- }
jz4780_i2c_set_speed(i2c);
- dev_info(&pdev->dev, "Bus frequency is %d KHz\n", i2c->speed);
+ dev_info(dev, "Bus frequency is %d KHz\n", i2c->speed);
if (i2c->cdata->version < ID_X1000) {
tmp = jz4780_i2c_readw(i2c, JZ4780_I2C_CTRL);
@@ -826,8 +826,8 @@ static int jz4780_i2c_probe(struct platform_device *pdev)
return ret;
i2c->irq = ret;
- ret = devm_request_irq(&pdev->dev, i2c->irq, jz4780_i2c_irq, 0,
- dev_name(&pdev->dev), i2c);
+ ret = devm_request_irq(dev, i2c->irq, jz4780_i2c_irq, 0,
+ dev_name(dev), i2c);
if (ret)
return ret;
--
2.39.0
Hi Rong, On Tue, Aug 27, 2024 at 11:48:41AM GMT, Rong Qianfeng wrote: > No more special handling needed here, so use dev_err_probe() > to simplify the code. > > While at it, use struct dev *dev to replace &pdev->dev to > further simplify the code. > > Use the macro definition HZ_PER_KHZ to replace the 1000. > > Signed-off-by: Rong Qianfeng <rongqianfeng@vivo.com> > --- > drivers/i2c/busses/i2c-jz4780.c | 40 ++++++++++++++++----------------- > 1 file changed, 20 insertions(+), 20 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c > index 92cc5b091137..72823a0f39c2 100644 > --- a/drivers/i2c/busses/i2c-jz4780.c > +++ b/drivers/i2c/busses/i2c-jz4780.c > @@ -23,6 +23,7 @@ > #include <linux/sched.h> > #include <linux/slab.h> > #include <linux/time.h> > +#include <linux/units.h> > > #define JZ4780_I2C_CTRL 0x00 > #define JZ4780_I2C_TAR 0x04 > @@ -764,14 +765,15 @@ static int jz4780_i2c_probe(struct platform_device *pdev) > unsigned int clk_freq = 0; > unsigned short tmp; > struct jz4780_i2c *i2c; > + struct device *dev = &pdev->dev; I'm not a big fan of this change. There is not much gain in polluting git bisect in order to shorten pdev->dev to a single dev. However, I like the /dev_err/dev_err_probe/. I will take the first two patches from this series, but I will leave this if anyone else has a stronger opinion. If you want, you can send just this one patch with just the dev_err_probe() change. Thanks, Andi
On Mon, Sep 09, 2024 at 10:23:30AM +0200, Andi Shyti wrote: > On Tue, Aug 27, 2024 at 11:48:41AM GMT, Rong Qianfeng wrote: ... > > + struct device *dev = &pdev->dev; > > I'm not a big fan of this change. There is not much gain in > polluting git bisect in order to shorten pdev->dev to a single > dev. > > However, I like the /dev_err/dev_err_probe/. > > I will take the first two patches from this series, but I will > leave this if anyone else has a stronger opinion. If you want, > you can send just this one patch with just the dev_err_probe() > change. Usually I combined this with conversion to dev_err_probe() et al. so it makes new lines a bit shorter and hence readability a bit better. On its own it's indeed questionable change. -- With Best Regards, Andy Shevchenko
Hi Andi, > I'm not a big fan of this change. There is not much gain in > polluting git bisect in order to shorten pdev->dev to a single > dev. > > However, I like the /dev_err/dev_err_probe/. > > I will take the first two patches from this series, but I will > leave this if anyone else has a stronger opinion. If you want, > you can send just this one patch with just the dev_err_probe() > change. Thanks for taking the time to review my patch! Please take the first two patches, I don't plan to submit another patch that only modifies dev_err(). Best Regards, Qianfeng
Hi Rong, On Mon, Sep 09, 2024 at 04:58:10PM GMT, Rong Qianfeng wrote: > > I'm not a big fan of this change. There is not much gain in > > polluting git bisect in order to shorten pdev->dev to a single > > dev. > > > > However, I like the /dev_err/dev_err_probe/. > > > > I will take the first two patches from this series, but I will > > leave this if anyone else has a stronger opinion. If you want, > > you can send just this one patch with just the dev_err_probe() > > change. > Thanks for taking the time to review my patch! > Please take the first two patches, I don't plan to submit another > patch that only modifies dev_err(). Sorry, I forgot to write it, I merged the first two in i2c/i2c-host. If you want to send one to change dev_err with dev_err_probe separately I will take it. Thanks, Andi
Hi Andi, 在 2024/9/10 3:24, Andi Shyti 写道: > On Mon, Sep 09, 2024 at 04:58:10PM GMT, Rong Qianfeng wrote: >>> I'm not a big fan of this change. There is not much gain in >>> polluting git bisect in order to shorten pdev->dev to a single >>> dev. >>> >>> However, I like the /dev_err/dev_err_probe/. >>> >>> I will take the first two patches from this series, but I will >>> leave this if anyone else has a stronger opinion. If you want, >>> you can send just this one patch with just the dev_err_probe() >>> change. >> Thanks for taking the time to review my patch! >> Please take the first two patches, I don't plan to submit another >> patch that only modifies dev_err(). > Sorry, I forgot to write it, I merged the first two in > i2c/i2c-host. > > If you want to send one to change dev_err with dev_err_probe > separately I will take it. ok, I got it, thanks. Best Regards, Qianfeng
© 2016 - 2025 Red Hat, Inc.