In current zram, we use DEVICE_ATTR() to define sys device attributes.
SO, we need to set (S_IRUGO | S_IWUSR) permission and other
arguments manually.
Linux kernel has already provided macro DEVICE_ATTR_[RW|RO|WO] to define
sys device attribute. It is simple and readable.
This patch uses kernel defined macro DEVICE_ATTR_[RW|RO|WO] to define
zram device attribute.
Signed-off-by: Ganesh Mahendran <[email protected]>
---
drivers/block/zram/zram_drv.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 8eb0d85..53fbd61 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -44,15 +44,14 @@ static const char *default_compressor = "lzo";
static unsigned int num_devices = 1;
#define ZRAM_ATTR_RO(name) \
-static ssize_t zram_attr_##name##_show(struct device *d, \
+static ssize_t name##_show(struct device *d, \
struct device_attribute *attr, char *b) \
{ \
struct zram *zram = dev_to_zram(d); \
return scnprintf(b, PAGE_SIZE, "%llu\n", \
(u64)atomic64_read(&zram->stats.name)); \
} \
-static struct device_attribute dev_attr_##name = \
- __ATTR(name, S_IRUGO, zram_attr_##name##_show, NULL);
+static DEVICE_ATTR_RO(name);
static inline int init_done(struct zram *zram)
{
@@ -994,20 +993,15 @@ static const struct block_device_operations zram_devops = {
.owner = THIS_MODULE
};
-static DEVICE_ATTR(disksize, S_IRUGO | S_IWUSR,
- disksize_show, disksize_store);
-static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL);
-static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store);
-static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL);
-static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
-static DEVICE_ATTR(mem_limit, S_IRUGO | S_IWUSR, mem_limit_show,
- mem_limit_store);
-static DEVICE_ATTR(mem_used_max, S_IRUGO | S_IWUSR, mem_used_max_show,
- mem_used_max_store);
-static DEVICE_ATTR(max_comp_streams, S_IRUGO | S_IWUSR,
- max_comp_streams_show, max_comp_streams_store);
-static DEVICE_ATTR(comp_algorithm, S_IRUGO | S_IWUSR,
- comp_algorithm_show, comp_algorithm_store);
+static DEVICE_ATTR_RW(disksize);
+static DEVICE_ATTR_RO(initstate);
+static DEVICE_ATTR_WO(reset);
+static DEVICE_ATTR_RO(orig_data_size);
+static DEVICE_ATTR_RO(mem_used_total);
+static DEVICE_ATTR_RW(mem_limit);
+static DEVICE_ATTR_RW(mem_used_max);
+static DEVICE_ATTR_RW(max_comp_streams);
+static DEVICE_ATTR_RW(comp_algorithm);
ZRAM_ATTR_RO(num_reads);
ZRAM_ATTR_RO(num_writes);
--
1.7.9.5
On 12/03/2014 01:38 PM, Ganesh Mahendran wrote:
> In current zram, we use DEVICE_ATTR() to define sys device attributes.
> SO, we need to set (S_IRUGO | S_IWUSR) permission and other
> arguments manually.
> Linux kernel has already provided macro DEVICE_ATTR_[RW|RO|WO] to define
> sys device attribute. It is simple and readable.
It does look cleaner.
>
> This patch uses kernel defined macro DEVICE_ATTR_[RW|RO|WO] to define
> zram device attribute.
>
> Signed-off-by: Ganesh Mahendran <[email protected]>
Acked-by: Jerome Marchand <[email protected]>
Thanks,
Jerome
> ---
> drivers/block/zram/zram_drv.c | 28 +++++++++++-----------------
> 1 file changed, 11 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 8eb0d85..53fbd61 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -44,15 +44,14 @@ static const char *default_compressor = "lzo";
> static unsigned int num_devices = 1;
>
> #define ZRAM_ATTR_RO(name) \
> -static ssize_t zram_attr_##name##_show(struct device *d, \
> +static ssize_t name##_show(struct device *d, \
> struct device_attribute *attr, char *b) \
> { \
> struct zram *zram = dev_to_zram(d); \
> return scnprintf(b, PAGE_SIZE, "%llu\n", \
> (u64)atomic64_read(&zram->stats.name)); \
> } \
> -static struct device_attribute dev_attr_##name = \
> - __ATTR(name, S_IRUGO, zram_attr_##name##_show, NULL);
> +static DEVICE_ATTR_RO(name);
>
> static inline int init_done(struct zram *zram)
> {
> @@ -994,20 +993,15 @@ static const struct block_device_operations zram_devops = {
> .owner = THIS_MODULE
> };
>
> -static DEVICE_ATTR(disksize, S_IRUGO | S_IWUSR,
> - disksize_show, disksize_store);
> -static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL);
> -static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store);
> -static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL);
> -static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
> -static DEVICE_ATTR(mem_limit, S_IRUGO | S_IWUSR, mem_limit_show,
> - mem_limit_store);
> -static DEVICE_ATTR(mem_used_max, S_IRUGO | S_IWUSR, mem_used_max_show,
> - mem_used_max_store);
> -static DEVICE_ATTR(max_comp_streams, S_IRUGO | S_IWUSR,
> - max_comp_streams_show, max_comp_streams_store);
> -static DEVICE_ATTR(comp_algorithm, S_IRUGO | S_IWUSR,
> - comp_algorithm_show, comp_algorithm_store);
> +static DEVICE_ATTR_RW(disksize);
> +static DEVICE_ATTR_RO(initstate);
> +static DEVICE_ATTR_WO(reset);
> +static DEVICE_ATTR_RO(orig_data_size);
> +static DEVICE_ATTR_RO(mem_used_total);
> +static DEVICE_ATTR_RW(mem_limit);
> +static DEVICE_ATTR_RW(mem_used_max);
> +static DEVICE_ATTR_RW(max_comp_streams);
> +static DEVICE_ATTR_RW(comp_algorithm);
>
> ZRAM_ATTR_RO(num_reads);
> ZRAM_ATTR_RO(num_writes);
>