diff mbox series

[v1,2/5] iio: pressure: bmp280: Use IIO_DEVICE_ATTR_RO macro

Message ID 20200317101813.30829-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1,1/5] iio: pressure: bmp280: Tolerate IRQ before registering | expand

Commit Message

Andy Shevchenko March 17, 2020, 10:18 a.m. UTC
Use the IIO_DEVICE_ATTR_RO macro to create the device attributes.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/pressure/bmp280-core.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

Comments

Jonathan Cameron March 22, 2020, 5:16 p.m. UTC | #1
On Tue, 17 Mar 2020 12:18:10 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Use the IIO_DEVICE_ATTR_RO macro to create the device attributes.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Hmm. Minor gain but fair enough I guess.

Could consider using the core support _available attributes instead.

I'm not usually fussy about moving drivers over to that unless we have
an in kernel consumer, but if you are going to touch the code it
might be nice to move to them :)

Jonathan

> ---
>  drivers/iio/pressure/bmp280-core.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 5e229b95308e..25be3ff1a6ab 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -588,7 +588,7 @@ static ssize_t bmp280_show_avail(char *buf, const int *vals, const int n)
>  	return len;
>  }
>  
> -static ssize_t bmp280_show_temp_oversampling_avail(struct device *dev,
> +static ssize_t in_temp_oversampling_ratio_available_show(struct device *dev,
>  				struct device_attribute *attr, char *buf)
>  {
>  	struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev));
> @@ -596,8 +596,9 @@ static ssize_t bmp280_show_temp_oversampling_avail(struct device *dev,
>  	return bmp280_show_avail(buf, data->chip_info->oversampling_temp_avail,
>  				 data->chip_info->num_oversampling_temp_avail);
>  }
> +static IIO_DEVICE_ATTR_RO(in_temp_oversampling_ratio_available, 0);
>  
> -static ssize_t bmp280_show_press_oversampling_avail(struct device *dev,
> +static ssize_t in_pressure_oversampling_ratio_available_show(struct device *dev,
>  				struct device_attribute *attr, char *buf)
>  {
>  	struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev));
> @@ -605,17 +606,12 @@ static ssize_t bmp280_show_press_oversampling_avail(struct device *dev,
>  	return bmp280_show_avail(buf, data->chip_info->oversampling_press_avail,
>  				 data->chip_info->num_oversampling_press_avail);
>  }
> -
> -static IIO_DEVICE_ATTR(in_temp_oversampling_ratio_available,
> -	S_IRUGO, bmp280_show_temp_oversampling_avail, NULL, 0);
> -
> -static IIO_DEVICE_ATTR(in_pressure_oversampling_ratio_available,
> -	S_IRUGO, bmp280_show_press_oversampling_avail, NULL, 0);
> +static IIO_DEVICE_ATTR_RO(in_pressure_oversampling_ratio_available, 0);
>  
>  static struct attribute *bmp280_attributes[] = {
>  	&iio_dev_attr_in_temp_oversampling_ratio_available.dev_attr.attr,
>  	&iio_dev_attr_in_pressure_oversampling_ratio_available.dev_attr.attr,
> -	NULL,
> +	NULL
>  };
>  
>  static const struct attribute_group bmp280_attrs_group = {
Andy Shevchenko March 22, 2020, 9:17 p.m. UTC | #2
On Sun, Mar 22, 2020 at 7:17 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Tue, 17 Mar 2020 12:18:10 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>
> > Use the IIO_DEVICE_ATTR_RO macro to create the device attributes.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Hmm. Minor gain but fair enough I guess.
>
> Could consider using the core support _available attributes instead.
>
> I'm not usually fussy about moving drivers over to that unless we have
> an in kernel consumer, but if you are going to touch the code it
> might be nice to move to them :)

Any good driver as an example? Or even conversion change done for one?
Jonathan Cameron March 23, 2020, 9:38 a.m. UTC | #3
On Sun, 22 Mar 2020 23:17:07 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Sun, Mar 22, 2020 at 7:17 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > On Tue, 17 Mar 2020 12:18:10 +0200
> > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> >  
> > > Use the IIO_DEVICE_ATTR_RO macro to create the device attributes.
> > >
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>  
> >
> > Hmm. Minor gain but fair enough I guess.
> >
> > Could consider using the core support _available attributes instead.
> >
> > I'm not usually fussy about moving drivers over to that unless we have
> > an in kernel consumer, but if you are going to touch the code it
> > might be nice to move to them :)  
> 
> Any good driver as an example? Or even conversion change done for one?
> 


Grep read_avail and you will find a few.  drivers/iio/light/tsl2772.c looks
superficially similar to what would be needed here.

Jonathan
diff mbox series

Patch

diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 5e229b95308e..25be3ff1a6ab 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -588,7 +588,7 @@  static ssize_t bmp280_show_avail(char *buf, const int *vals, const int n)
 	return len;
 }
 
-static ssize_t bmp280_show_temp_oversampling_avail(struct device *dev,
+static ssize_t in_temp_oversampling_ratio_available_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
 	struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev));
@@ -596,8 +596,9 @@  static ssize_t bmp280_show_temp_oversampling_avail(struct device *dev,
 	return bmp280_show_avail(buf, data->chip_info->oversampling_temp_avail,
 				 data->chip_info->num_oversampling_temp_avail);
 }
+static IIO_DEVICE_ATTR_RO(in_temp_oversampling_ratio_available, 0);
 
-static ssize_t bmp280_show_press_oversampling_avail(struct device *dev,
+static ssize_t in_pressure_oversampling_ratio_available_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
 	struct bmp280_data *data = iio_priv(dev_to_iio_dev(dev));
@@ -605,17 +606,12 @@  static ssize_t bmp280_show_press_oversampling_avail(struct device *dev,
 	return bmp280_show_avail(buf, data->chip_info->oversampling_press_avail,
 				 data->chip_info->num_oversampling_press_avail);
 }
-
-static IIO_DEVICE_ATTR(in_temp_oversampling_ratio_available,
-	S_IRUGO, bmp280_show_temp_oversampling_avail, NULL, 0);
-
-static IIO_DEVICE_ATTR(in_pressure_oversampling_ratio_available,
-	S_IRUGO, bmp280_show_press_oversampling_avail, NULL, 0);
+static IIO_DEVICE_ATTR_RO(in_pressure_oversampling_ratio_available, 0);
 
 static struct attribute *bmp280_attributes[] = {
 	&iio_dev_attr_in_temp_oversampling_ratio_available.dev_attr.attr,
 	&iio_dev_attr_in_pressure_oversampling_ratio_available.dev_attr.attr,
-	NULL,
+	NULL
 };
 
 static const struct attribute_group bmp280_attrs_group = {