linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mtd: core: add and use MTD_DEVICE_ATTR_RO/RW() helper macros to simplify code
@ 2021-06-03 12:53 Zhen Lei
  2021-06-03 12:53 ` [PATCH 1/2] mtd: core: add MTD_DEVICE_ATTR_RO/RW() helper macros Zhen Lei
  2021-06-03 12:53 ` [PATCH 2/2] mtd: core: use " Zhen Lei
  0 siblings, 2 replies; 5+ messages in thread
From: Zhen Lei @ 2021-06-03 12:53 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-mtd, linux-kernel
  Cc: Zhen Lei

List of changed function names:
mtd_ecc_stats_corrected_show	--> mtd_corrected_bits_show	//MTD_DEVICE_ATTR_RO(corrected_bits)	/* ecc stats corrected */
mtd_ecc_stats_errors_show	--> mtd_ecc_failures_show	//MTD_DEVICE_ATTR_RO(ecc_failures)	/* ecc stats errors */
mtd_badblocks_show		--> mtd_bad_blocks_show		//MTD_DEVICE_ATTR_RO(bad_blocks)
mtd_bbtblocks_show		--> mtd_bbt_blocks_show		//MTD_DEVICE_ATTR_RO(bbt_blocks)


Zhen Lei (2):
  mtd: core: add MTD_DEVICE_ATTR_RO/RW() helper macros
  mtd: core: use MTD_DEVICE_ATTR_RO/RW() helper macros

 drivers/mtd/mtdcore.c | 52 ++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 25 deletions(-)

-- 
2.26.0.106.g9fadedd



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] mtd: core: add MTD_DEVICE_ATTR_RO/RW() helper macros
  2021-06-03 12:53 [PATCH 0/2] mtd: core: add and use MTD_DEVICE_ATTR_RO/RW() helper macros to simplify code Zhen Lei
@ 2021-06-03 12:53 ` Zhen Lei
  2021-06-11 19:00   ` Miquel Raynal
  2021-06-03 12:53 ` [PATCH 2/2] mtd: core: use " Zhen Lei
  1 sibling, 1 reply; 5+ messages in thread
From: Zhen Lei @ 2021-06-03 12:53 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-mtd, linux-kernel
  Cc: Zhen Lei

Compared with the definition of DEVICE_ATTR_RO/RW(), the read and write
function names of the sysfs attribute have an additional "mtd_" prefix.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 drivers/mtd/mtdcore.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index ce514305f8f756e..770f64d6701567a 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -96,6 +96,12 @@ static void mtd_release(struct device *dev)
 	device_destroy(&mtd_class, index + 1);
 }
 
+#define MTD_DEVICE_ATTR_RO(name) \
+static DEVICE_ATTR(name, 0444, mtd_##name##_show, NULL)
+
+#define MTD_DEVICE_ATTR_RW(name) \
+static DEVICE_ATTR(name, 0644, mtd_##name##_show, mtd_##name##_store)
+
 static ssize_t mtd_type_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
-- 
2.26.0.106.g9fadedd



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mtd: core: use MTD_DEVICE_ATTR_RO/RW() helper macros
  2021-06-03 12:53 [PATCH 0/2] mtd: core: add and use MTD_DEVICE_ATTR_RO/RW() helper macros to simplify code Zhen Lei
  2021-06-03 12:53 ` [PATCH 1/2] mtd: core: add MTD_DEVICE_ATTR_RO/RW() helper macros Zhen Lei
@ 2021-06-03 12:53 ` Zhen Lei
  2021-06-11 19:00   ` Miquel Raynal
  1 sibling, 1 reply; 5+ messages in thread
From: Zhen Lei @ 2021-06-03 12:53 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-mtd, linux-kernel
  Cc: Zhen Lei

Use MTD_DEVICE_ATTR_RO/RW() helper macros instead of plain DEVICE_ATTR(),
which makes the code a bit shorter and easier to read.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 drivers/mtd/mtdcore.c | 46 ++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 770f64d6701567a..b5ccd3037788a24 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -139,7 +139,7 @@ static ssize_t mtd_type_show(struct device *dev,
 
 	return sysfs_emit(buf, "%s\n", type);
 }
-static DEVICE_ATTR(type, S_IRUGO, mtd_type_show, NULL);
+MTD_DEVICE_ATTR_RO(type);
 
 static ssize_t mtd_flags_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -148,7 +148,7 @@ static ssize_t mtd_flags_show(struct device *dev,
 
 	return sysfs_emit(buf, "0x%lx\n", (unsigned long)mtd->flags);
 }
-static DEVICE_ATTR(flags, S_IRUGO, mtd_flags_show, NULL);
+MTD_DEVICE_ATTR_RO(flags);
 
 static ssize_t mtd_size_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -157,7 +157,7 @@ static ssize_t mtd_size_show(struct device *dev,
 
 	return sysfs_emit(buf, "%llu\n", (unsigned long long)mtd->size);
 }
-static DEVICE_ATTR(size, S_IRUGO, mtd_size_show, NULL);
+MTD_DEVICE_ATTR_RO(size);
 
 static ssize_t mtd_erasesize_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -166,7 +166,7 @@ static ssize_t mtd_erasesize_show(struct device *dev,
 
 	return sysfs_emit(buf, "%lu\n", (unsigned long)mtd->erasesize);
 }
-static DEVICE_ATTR(erasesize, S_IRUGO, mtd_erasesize_show, NULL);
+MTD_DEVICE_ATTR_RO(erasesize);
 
 static ssize_t mtd_writesize_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -175,7 +175,7 @@ static ssize_t mtd_writesize_show(struct device *dev,
 
 	return sysfs_emit(buf, "%lu\n", (unsigned long)mtd->writesize);
 }
-static DEVICE_ATTR(writesize, S_IRUGO, mtd_writesize_show, NULL);
+MTD_DEVICE_ATTR_RO(writesize);
 
 static ssize_t mtd_subpagesize_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -185,7 +185,7 @@ static ssize_t mtd_subpagesize_show(struct device *dev,
 
 	return sysfs_emit(buf, "%u\n", subpagesize);
 }
-static DEVICE_ATTR(subpagesize, S_IRUGO, mtd_subpagesize_show, NULL);
+MTD_DEVICE_ATTR_RO(subpagesize);
 
 static ssize_t mtd_oobsize_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -194,7 +194,7 @@ static ssize_t mtd_oobsize_show(struct device *dev,
 
 	return sysfs_emit(buf, "%lu\n", (unsigned long)mtd->oobsize);
 }
-static DEVICE_ATTR(oobsize, S_IRUGO, mtd_oobsize_show, NULL);
+MTD_DEVICE_ATTR_RO(oobsize);
 
 static ssize_t mtd_oobavail_show(struct device *dev,
 				 struct device_attribute *attr, char *buf)
@@ -203,7 +203,7 @@ static ssize_t mtd_oobavail_show(struct device *dev,
 
 	return sysfs_emit(buf, "%u\n", mtd->oobavail);
 }
-static DEVICE_ATTR(oobavail, S_IRUGO, mtd_oobavail_show, NULL);
+MTD_DEVICE_ATTR_RO(oobavail);
 
 static ssize_t mtd_numeraseregions_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -212,8 +212,7 @@ static ssize_t mtd_numeraseregions_show(struct device *dev,
 
 	return sysfs_emit(buf, "%u\n", mtd->numeraseregions);
 }
-static DEVICE_ATTR(numeraseregions, S_IRUGO, mtd_numeraseregions_show,
-	NULL);
+MTD_DEVICE_ATTR_RO(numeraseregions);
 
 static ssize_t mtd_name_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -222,7 +221,7 @@ static ssize_t mtd_name_show(struct device *dev,
 
 	return sysfs_emit(buf, "%s\n", mtd->name);
 }
-static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL);
+MTD_DEVICE_ATTR_RO(name);
 
 static ssize_t mtd_ecc_strength_show(struct device *dev,
 				     struct device_attribute *attr, char *buf)
@@ -231,7 +230,7 @@ static ssize_t mtd_ecc_strength_show(struct device *dev,
 
 	return sysfs_emit(buf, "%u\n", mtd->ecc_strength);
 }
-static DEVICE_ATTR(ecc_strength, S_IRUGO, mtd_ecc_strength_show, NULL);
+MTD_DEVICE_ATTR_RO(ecc_strength);
 
 static ssize_t mtd_bitflip_threshold_show(struct device *dev,
 					  struct device_attribute *attr,
@@ -257,9 +256,7 @@ static ssize_t mtd_bitflip_threshold_store(struct device *dev,
 	mtd->bitflip_threshold = bitflip_threshold;
 	return count;
 }
-static DEVICE_ATTR(bitflip_threshold, S_IRUGO | S_IWUSR,
-		   mtd_bitflip_threshold_show,
-		   mtd_bitflip_threshold_store);
+MTD_DEVICE_ATTR_RW(bitflip_threshold);
 
 static ssize_t mtd_ecc_step_size_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -269,9 +266,9 @@ static ssize_t mtd_ecc_step_size_show(struct device *dev,
 	return sysfs_emit(buf, "%u\n", mtd->ecc_step_size);
 
 }
-static DEVICE_ATTR(ecc_step_size, S_IRUGO, mtd_ecc_step_size_show, NULL);
+MTD_DEVICE_ATTR_RO(ecc_step_size);
 
-static ssize_t mtd_ecc_stats_corrected_show(struct device *dev,
+static ssize_t mtd_corrected_bits_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
 	struct mtd_info *mtd = dev_get_drvdata(dev);
@@ -279,10 +276,9 @@ static ssize_t mtd_ecc_stats_corrected_show(struct device *dev,
 
 	return sysfs_emit(buf, "%u\n", ecc_stats->corrected);
 }
-static DEVICE_ATTR(corrected_bits, S_IRUGO,
-		   mtd_ecc_stats_corrected_show, NULL);
+MTD_DEVICE_ATTR_RO(corrected_bits);	/* ecc stats corrected */
 
-static ssize_t mtd_ecc_stats_errors_show(struct device *dev,
+static ssize_t mtd_ecc_failures_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
 	struct mtd_info *mtd = dev_get_drvdata(dev);
@@ -290,9 +286,9 @@ static ssize_t mtd_ecc_stats_errors_show(struct device *dev,
 
 	return sysfs_emit(buf, "%u\n", ecc_stats->failed);
 }
-static DEVICE_ATTR(ecc_failures, S_IRUGO, mtd_ecc_stats_errors_show, NULL);
+MTD_DEVICE_ATTR_RO(ecc_failures);	/* ecc stats errors */
 
-static ssize_t mtd_badblocks_show(struct device *dev,
+static ssize_t mtd_bad_blocks_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
 	struct mtd_info *mtd = dev_get_drvdata(dev);
@@ -300,9 +296,9 @@ static ssize_t mtd_badblocks_show(struct device *dev,
 
 	return sysfs_emit(buf, "%u\n", ecc_stats->badblocks);
 }
-static DEVICE_ATTR(bad_blocks, S_IRUGO, mtd_badblocks_show, NULL);
+MTD_DEVICE_ATTR_RO(bad_blocks);
 
-static ssize_t mtd_bbtblocks_show(struct device *dev,
+static ssize_t mtd_bbt_blocks_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
 	struct mtd_info *mtd = dev_get_drvdata(dev);
@@ -310,7 +306,7 @@ static ssize_t mtd_bbtblocks_show(struct device *dev,
 
 	return sysfs_emit(buf, "%u\n", ecc_stats->bbtblocks);
 }
-static DEVICE_ATTR(bbt_blocks, S_IRUGO, mtd_bbtblocks_show, NULL);
+MTD_DEVICE_ATTR_RO(bbt_blocks);
 
 static struct attribute *mtd_attrs[] = {
 	&dev_attr_type.attr,
-- 
2.26.0.106.g9fadedd



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mtd: core: use MTD_DEVICE_ATTR_RO/RW() helper macros
  2021-06-03 12:53 ` [PATCH 2/2] mtd: core: use " Zhen Lei
@ 2021-06-11 19:00   ` Miquel Raynal
  0 siblings, 0 replies; 5+ messages in thread
From: Miquel Raynal @ 2021-06-11 19:00 UTC (permalink / raw)
  To: Zhen Lei, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-mtd, linux-kernel

On Thu, 2021-06-03 at 12:53:23 UTC, Zhen Lei wrote:
> Use MTD_DEVICE_ATTR_RO/RW() helper macros instead of plain DEVICE_ATTR(),
> which makes the code a bit shorter and easier to read.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mtd: core: add MTD_DEVICE_ATTR_RO/RW() helper macros
  2021-06-03 12:53 ` [PATCH 1/2] mtd: core: add MTD_DEVICE_ATTR_RO/RW() helper macros Zhen Lei
@ 2021-06-11 19:00   ` Miquel Raynal
  0 siblings, 0 replies; 5+ messages in thread
From: Miquel Raynal @ 2021-06-11 19:00 UTC (permalink / raw)
  To: Zhen Lei, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-mtd, linux-kernel

On Thu, 2021-06-03 at 12:53:22 UTC, Zhen Lei wrote:
> Compared with the definition of DEVICE_ATTR_RO/RW(), the read and write
> function names of the sysfs attribute have an additional "mtd_" prefix.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-11 19:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-03 12:53 [PATCH 0/2] mtd: core: add and use MTD_DEVICE_ATTR_RO/RW() helper macros to simplify code Zhen Lei
2021-06-03 12:53 ` [PATCH 1/2] mtd: core: add MTD_DEVICE_ATTR_RO/RW() helper macros Zhen Lei
2021-06-11 19:00   ` Miquel Raynal
2021-06-03 12:53 ` [PATCH 2/2] mtd: core: use " Zhen Lei
2021-06-11 19:00   ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).