Skip to contentSkip to conversation

zcomp: Use ARRAY_SIZE() for backends list

PATCH Superseded Andy Shevchenko 2 participants 5 messages Mar 23, 2020 – May 8, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zcomp: Use ARRAY_SIZE() for backends list

Instead of keeping NULL terminated array switch to use ARRAY_SIZE() which helps to further clean up.

---
 drivers/block/zram/zcomp.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/block/zram/zcomp.c +3 -4
index 1a8564a79d8d..e78e7a2ccfd5 100644
@@ -29,7 +29,6 @@ static const char * const backends[] = {
 #if IS_ENABLED(CONFIG_CRYPTO_ZSTD)
 	"zstd",
 #endif
-	NULL
 };
 
 static void zcomp_strm_free(struct zcomp_strm *zstrm)
@@ -67,7 +66,7 @@ bool zcomp_available_algorithm(const char *comp)
 {
 	int i;
 
-	i = __sysfs_match_string(backends, -1, comp);
+	i = sysfs_match_string(backends, comp);
 	if (i >= 0)
 		return true;
 
@@ -86,9 +85,9 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
 {
 	bool known_algorithm = false;
 	ssize_t sz = 0;
-	int i = 0;
+	int i;
 
-	for (; backends[i]; i++) {
+	for (i = 0; i < ARRAY_SIZE(backends); i++) {
 		if (!strcmp(comp, backends[i])) {
 			known_algorithm = true;
 			sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Andy Shevchenko

Instead of keeping NULL terminated array switch to use ARRAY_SIZE() which helps to further clean up.

Any comments on this?

Quoted 41 lines
---
 drivers/block/zram/zcomp.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/block/zram/zcomp.c +3 -4
index 1a8564a79d8d..e78e7a2ccfd5 100644
@@ -29,7 +29,6 @@ static const char * const backends[] = {
 #if IS_ENABLED(CONFIG_CRYPTO_ZSTD)
 	"zstd",
 #endif
-	NULL
 };
 
 static void zcomp_strm_free(struct zcomp_strm *zstrm)
@@ -67,7 +66,7 @@ bool zcomp_available_algorithm(const char *comp)
 {
 	int i;
 
-	i = __sysfs_match_string(backends, -1, comp);
+	i = sysfs_match_string(backends, comp);
 	if (i >= 0)
 		return true;
 
@@ -86,9 +85,9 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
 {
 	bool known_algorithm = false;
 	ssize_t sz = 0;
-	int i = 0;
+	int i;
 
-	for (; backends[i]; i++) {
+	for (i = 0; i < ARRAY_SIZE(backends); i++) {
 		if (!strcmp(comp, backends[i])) {
 			known_algorithm = true;
 			sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
Signature · 1 line
2.25.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Instead of keeping NULL terminated array switch to use ARRAY_SIZE() which helps to further clean up.

Any comments on this?

Should I do anything about this?

Quoted 48 lines
Quoted 42 lines
---
 drivers/block/zram/zcomp.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/block/zram/zcomp.c +3 -4
index 1a8564a79d8d..e78e7a2ccfd5 100644
@@ -29,7 +29,6 @@ static const char * const backends[] = {
 #if IS_ENABLED(CONFIG_CRYPTO_ZSTD)
 	"zstd",
 #endif
-	NULL
 };
 
 static void zcomp_strm_free(struct zcomp_strm *zstrm)
@@ -67,7 +66,7 @@ bool zcomp_available_algorithm(const char *comp)
 {
 	int i;
 
-	i = __sysfs_match_string(backends, -1, comp);
+	i = sysfs_match_string(backends, comp);
 	if (i >= 0)
 		return true;
 
@@ -86,9 +85,9 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
 {
 	bool known_algorithm = false;
 	ssize_t sz = 0;
-	int i = 0;
+	int i;
 
-	for (; backends[i]; i++) {
+	for (i = 0; i < ARRAY_SIZE(backends); i++) {
 		if (!strcmp(comp, backends[i])) {
 			known_algorithm = true;
 			sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
Signature · 1 line
2.25.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Acked-by
#3 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Instead of keeping NULL terminated array switch to use ARRAY_SIZE() which helps to further clean up.

Any comments on this?

Sorry for the late. I lost this patch in my mail box. Could you resend this patch with Ccing Andrew Morton and Sergey Senozhatsky with me?

Thanks.

Quoted 49 lines
Quoted 43 lines
---
 drivers/block/zram/zcomp.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/block/zram/zcomp.c +3 -4
index 1a8564a79d8d..e78e7a2ccfd5 100644
@@ -29,7 +29,6 @@ static const char * const backends[] = {
 #if IS_ENABLED(CONFIG_CRYPTO_ZSTD)
 	"zstd",
 #endif
-	NULL
 };
 
 static void zcomp_strm_free(struct zcomp_strm *zstrm)
@@ -67,7 +66,7 @@ bool zcomp_available_algorithm(const char *comp)
 {
 	int i;
 
-	i = __sysfs_match_string(backends, -1, comp);
+	i = sysfs_match_string(backends, comp);
 	if (i >= 0)
 		return true;
 
@@ -86,9 +85,9 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
 {
 	bool known_algorithm = false;
 	ssize_t sz = 0;
-	int i = 0;
+	int i;
 
-	for (; backends[i]; i++) {
+	for (i = 0; i < ARRAY_SIZE(backends); i++) {
 		if (!strcmp(comp, backends[i])) {
 			known_algorithm = true;
 			sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
Signature · 1 line
2.25.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 8 lines · Minchan Kim
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Instead of keeping NULL terminated array switch to use ARRAY_SIZE() which helps to further clean up.

Any comments on this?

Thanks!

Quoted 2 lines

Sorry for the late. I lost this patch in my mail box. Could you resend this patch with Ccing Andrew Morton and Sergey Senozhatsky with me?

Done.

Signature · 2 lines
With Best Regards,
Andy Shevchenko