2023-08-05 23:38:16

by Angel Iglesias

[permalink] [raw]
Subject: [PATCH 0/2] iio: pressure: bmp280: Use i2c_get_match_data()

Minor cleanup of BMP280 i2c code and migration to the new helper function
i2c_get_match_data() instead of device_get_match_data().

Patch 1 reorders local variable declarations on probe function following
the reverse xmas tree to unify styles with other parts of the driver.

Patch 2 ports adtops the i2c_get_match_data() helper on the i2c probe.

Angel Iglesias (2):
iio: pressure: bmp280: i2c: Rearrange vars in reverse xmas tree order
iio: pressure: bmp280: Use i2c_get_match_data

drivers/iio/pressure/bmp280-i2c.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)


base-commit: 6d9c5ae6a70c9e1017a7a252bc730d9168e219ce
--
2.41.0



2023-08-05 23:39:21

by Angel Iglesias

[permalink] [raw]
Subject: [PATCH 1/2] iio: pressure: bmp280: i2c: Rearrange vars in reverse xmas tree order

Minor cleanup reordering local variable declarations following reverse
christmas tree convention.

Signed-off-by: Angel Iglesias <[email protected]>

diff --git a/drivers/iio/pressure/bmp280-i2c.c b/drivers/iio/pressure/bmp280-i2c.c
index dbe630ad05b5..693eb1975fdc 100644
--- a/drivers/iio/pressure/bmp280-i2c.c
+++ b/drivers/iio/pressure/bmp280-i2c.c
@@ -7,9 +7,9 @@

static int bmp280_i2c_probe(struct i2c_client *client)
{
- struct regmap *regmap;
- const struct bmp280_chip_info *chip_info;
const struct i2c_device_id *id = i2c_client_get_device_id(client);
+ const struct bmp280_chip_info *chip_info;
+ struct regmap *regmap;

chip_info = device_get_match_data(&client->dev);
if (!chip_info)
--
2.41.0


2023-08-06 00:20:20

by Angel Iglesias

[permalink] [raw]
Subject: [PATCH 2/2] iio: pressure: bmp280: Use i2c_get_match_data

Replaces device_get_match_data() and fallback match_id logic by new
unified helper function i2c_get_match_data().

Signed-off-by: Angel Iglesias <[email protected]>

diff --git a/drivers/iio/pressure/bmp280-i2c.c b/drivers/iio/pressure/bmp280-i2c.c
index 693eb1975fdc..4ebaa4edc4fc 100644
--- a/drivers/iio/pressure/bmp280-i2c.c
+++ b/drivers/iio/pressure/bmp280-i2c.c
@@ -11,9 +11,9 @@ static int bmp280_i2c_probe(struct i2c_client *client)
const struct bmp280_chip_info *chip_info;
struct regmap *regmap;

- chip_info = device_get_match_data(&client->dev);
+ chip_info = i2c_get_match_data(client);
if (!chip_info)
- chip_info = (const struct bmp280_chip_info *) id->driver_data;
+ return -ENODEV;

regmap = devm_regmap_init_i2c(client, chip_info->regmap_config);
if (IS_ERR(regmap)) {
--
2.41.0


2023-08-06 11:37:01

by Uwe Kleine-König

[permalink] [raw]
Subject: Re: [PATCH 2/2] iio: pressure: bmp280: Use i2c_get_match_data

On Sun, Aug 06, 2023 at 01:15:03AM +0200, Angel Iglesias wrote:
> Replaces device_get_match_data() and fallback match_id logic by new
> unified helper function i2c_get_match_data().
>
> Signed-off-by: Angel Iglesias <[email protected]>
>
> diff --git a/drivers/iio/pressure/bmp280-i2c.c b/drivers/iio/pressure/bmp280-i2c.c
> index 693eb1975fdc..4ebaa4edc4fc 100644
> --- a/drivers/iio/pressure/bmp280-i2c.c
> +++ b/drivers/iio/pressure/bmp280-i2c.c
> @@ -11,9 +11,9 @@ static int bmp280_i2c_probe(struct i2c_client *client)
> const struct bmp280_chip_info *chip_info;
> struct regmap *regmap;
>
> - chip_info = device_get_match_data(&client->dev);
> + chip_info = i2c_get_match_data(client);
> if (!chip_info)
> - chip_info = (const struct bmp280_chip_info *) id->driver_data;
> + return -ENODEV;

the old code assumed that chip_info isn't NULL (implicitly by
dereferencing that pointer in the line below). I wouldn't change
semantics in a patch converting to a helper and so just do:

- chip_info = device_get_match_data(&client->dev);
+ chip_info = i2c_get_match_data(client);
- if (!chip_info)
- chip_info = (const struct bmp280_chip_info *) id->driver_data;

or alternatively, if you think adding a check is a good idea, add an
error message in the error path and mention the semantic change in the
commit log.

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | https://www.pengutronix.de/ |


Attachments:
(No filename) (1.51 kB)
signature.asc (499.00 B)
Download all attachments

2023-08-07 16:27:03

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 1/2] iio: pressure: bmp280: i2c: Rearrange vars in reverse xmas tree order

On Sun, Aug 06, 2023 at 01:15:02AM +0200, Angel Iglesias wrote:
> Minor cleanup reordering local variable declarations following reverse
> christmas tree convention.

What about other functions there? Are all of them ordered correctly?

--
With Best Regards,
Andy Shevchenko



2023-08-12 16:09:09

by Angel Iglesias

[permalink] [raw]
Subject: Re: [PATCH 2/2] iio: pressure: bmp280: Use i2c_get_match_data

On Sun, 2023-08-06 at 13:30 +0200, Uwe Kleine-König wrote:
> On Sun, Aug 06, 2023 at 01:15:03AM +0200, Angel Iglesias wrote:
> > Replaces device_get_match_data() and fallback match_id logic by new
> > unified helper function i2c_get_match_data().
> >
> > Signed-off-by: Angel Iglesias <[email protected]>
> >
> > diff --git a/drivers/iio/pressure/bmp280-i2c.c
> > b/drivers/iio/pressure/bmp280-i2c.c
> > index 693eb1975fdc..4ebaa4edc4fc 100644
> > --- a/drivers/iio/pressure/bmp280-i2c.c
> > +++ b/drivers/iio/pressure/bmp280-i2c.c
> > @@ -11,9 +11,9 @@ static int bmp280_i2c_probe(struct i2c_client *client)
> >         const struct bmp280_chip_info *chip_info;
> >         struct regmap *regmap;
> >  
> > -       chip_info = device_get_match_data(&client->dev);
> > +       chip_info = i2c_get_match_data(client);
> >         if (!chip_info)
> > -               chip_info = (const struct bmp280_chip_info *) id-
> > >driver_data;
> > +               return -ENODEV;
>
> the old code assumed that chip_info isn't NULL (implicitly by
> dereferencing that pointer in the line below). I wouldn't change
> semantics in a patch converting to a helper and so just do:
>
> -       chip_info = device_get_match_data(&client->dev);
> +       chip_info = i2c_get_match_data(client);
> -       if (!chip_info)
> -               chip_info = (const struct bmp280_chip_info *) id->driver_data;
>
> or alternatively, if you think adding a check is a good idea, add an
> error message in the error path and mention the semantic change in the
> commit log.
>

Oh I see. I didn't take into account all this. Thanks for your time

> Best regards
> Uwe
>
Kind regards
Angel


2023-08-12 16:54:44

by Angel Iglesias

[permalink] [raw]
Subject: Re: [PATCH 1/2] iio: pressure: bmp280: i2c: Rearrange vars in reverse xmas tree order

On Mon, 2023-08-07 at 18:43 +0300, Andy Shevchenko wrote:
> On Sun, Aug 06, 2023 at 01:15:02AM +0200, Angel Iglesias wrote:
> > Minor cleanup reordering local variable declarations following reverse
> > christmas tree convention.
>
> What about other functions there? Are all of them ordered correctly?
>
This one was a leftover from previous work I did on this driver. I will check
the rest of the drive and update it to follow the same convention if required.
Thank you for your time.

Kind regards
Angel