diff mbox series

[v1,14/22] iio: imu: st_lsm6dsx: Get platform data via dev_get_platdata()

Message ID 20240902222824.1145571-15-andy.shevchenko@gmail.com (mailing list archive)
State Accepted
Headers show
Series iio: use dev_get_platdata() to access platform_data | expand

Commit Message

Andy Shevchenko Sept. 2, 2024, 10:16 p.m. UTC
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Access to platform data via dev_get_platdata() getter to make code cleaner.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

Comments

Lorenzo Bianconi Sept. 3, 2024, 7:10 a.m. UTC | #1
> From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Access to platform data via dev_get_platdata() getter to make code cleaner.
> 
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index ed0267929725..3958b5e1a3f6 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -2132,14 +2132,11 @@ st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
>  			const struct st_lsm6dsx_reg **drdy_reg)
>  {
>  	struct device *dev = hw->dev;
> +	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);

nit: I guess you can move pdata pointer in the 'if' block, since it is just
used there.

Regards,
Lorenzo

>  	int err = 0, drdy_pin;
>  
> -	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0) {
> -		struct st_sensors_platform_data *pdata;
> -
> -		pdata = (struct st_sensors_platform_data *)dev->platform_data;
> +	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0)
>  		drdy_pin = pdata ? pdata->drdy_int_pin : 1;
> -	}
>  
>  	switch (drdy_pin) {
>  	case 1:
> @@ -2162,14 +2159,13 @@ st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
>  static int st_lsm6dsx_init_shub(struct st_lsm6dsx_hw *hw)
>  {
>  	const struct st_lsm6dsx_shub_settings *hub_settings;
> -	struct st_sensors_platform_data *pdata;
>  	struct device *dev = hw->dev;
> +	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
>  	unsigned int data;
>  	int err = 0;
>  
>  	hub_settings = &hw->settings->shub_settings;
>  
> -	pdata = (struct st_sensors_platform_data *)dev->platform_data;
>  	if (device_property_read_bool(dev, "st,pullups") ||
>  	    (pdata && pdata->pullups)) {
>  		if (hub_settings->pullup_en.sec_page) {
> @@ -2524,9 +2520,9 @@ static irqreturn_t st_lsm6dsx_sw_trigger_handler_thread(int irq,
>  
>  static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
>  {
> -	struct st_sensors_platform_data *pdata;
>  	const struct st_lsm6dsx_reg *reg;
>  	struct device *dev = hw->dev;
> +	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
>  	unsigned long irq_type;
>  	bool irq_active_low;
>  	int err;
> @@ -2554,7 +2550,6 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
>  	if (err < 0)
>  		return err;
>  
> -	pdata = (struct st_sensors_platform_data *)dev->platform_data;
>  	if (device_property_read_bool(dev, "drive-open-drain") ||
>  	    (pdata && pdata->open_drain)) {
>  		reg = &hw->settings->irq_config.od;
> @@ -2639,7 +2634,7 @@ static int st_lsm6dsx_init_regulators(struct device *dev)
>  int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
>  		     struct regmap *regmap)
>  {
> -	struct st_sensors_platform_data *pdata = dev->platform_data;
> +	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
>  	const struct st_lsm6dsx_shub_settings *hub_settings;
>  	struct st_lsm6dsx_hw *hw;
>  	const char *name = NULL;
> -- 
> 2.46.0
>
Andy Shevchenko Sept. 3, 2024, 10:38 a.m. UTC | #2
On Tue, Sep 3, 2024 at 10:11 AM Lorenzo Bianconi <lorenzo@kernel.org> wrote:

...

> >       struct device *dev = hw->dev;
> > +     const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
>
> nit: I guess you can move pdata pointer in the 'if' block, since it is just
> used there.

Yes, but it will increase the LoCs number by 3 for no benefit for each
of such cases.

> >       int err = 0, drdy_pin;
> >
> > -     if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0) {
> > -             struct st_sensors_platform_data *pdata;
> > -
> > -             pdata = (struct st_sensors_platform_data *)dev->platform_data;
> > +     if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0)
> >               drdy_pin = pdata ? pdata->drdy_int_pin : 1;
> > -     }
diff mbox series

Patch

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index ed0267929725..3958b5e1a3f6 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -2132,14 +2132,11 @@  st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
 			const struct st_lsm6dsx_reg **drdy_reg)
 {
 	struct device *dev = hw->dev;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	int err = 0, drdy_pin;
 
-	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0) {
-		struct st_sensors_platform_data *pdata;
-
-		pdata = (struct st_sensors_platform_data *)dev->platform_data;
+	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0)
 		drdy_pin = pdata ? pdata->drdy_int_pin : 1;
-	}
 
 	switch (drdy_pin) {
 	case 1:
@@ -2162,14 +2159,13 @@  st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
 static int st_lsm6dsx_init_shub(struct st_lsm6dsx_hw *hw)
 {
 	const struct st_lsm6dsx_shub_settings *hub_settings;
-	struct st_sensors_platform_data *pdata;
 	struct device *dev = hw->dev;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	unsigned int data;
 	int err = 0;
 
 	hub_settings = &hw->settings->shub_settings;
 
-	pdata = (struct st_sensors_platform_data *)dev->platform_data;
 	if (device_property_read_bool(dev, "st,pullups") ||
 	    (pdata && pdata->pullups)) {
 		if (hub_settings->pullup_en.sec_page) {
@@ -2524,9 +2520,9 @@  static irqreturn_t st_lsm6dsx_sw_trigger_handler_thread(int irq,
 
 static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 {
-	struct st_sensors_platform_data *pdata;
 	const struct st_lsm6dsx_reg *reg;
 	struct device *dev = hw->dev;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	unsigned long irq_type;
 	bool irq_active_low;
 	int err;
@@ -2554,7 +2550,6 @@  static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
 	if (err < 0)
 		return err;
 
-	pdata = (struct st_sensors_platform_data *)dev->platform_data;
 	if (device_property_read_bool(dev, "drive-open-drain") ||
 	    (pdata && pdata->open_drain)) {
 		reg = &hw->settings->irq_config.od;
@@ -2639,7 +2634,7 @@  static int st_lsm6dsx_init_regulators(struct device *dev)
 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 		     struct regmap *regmap)
 {
-	struct st_sensors_platform_data *pdata = dev->platform_data;
+	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
 	const struct st_lsm6dsx_shub_settings *hub_settings;
 	struct st_lsm6dsx_hw *hw;
 	const char *name = NULL;