diff mbox series

[v1] zcomp: Use ARRAY_SIZE() for backends list

Message ID 20200323175008.83393-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1] zcomp: Use ARRAY_SIZE() for backends list | expand

Commit Message

Andy Shevchenko March 23, 2020, 5:50 p.m. UTC
Instead of keeping NULL terminated array switch to use ARRAY_SIZE()
which helps to further clean up.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/block/zram/zcomp.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Andy Shevchenko April 15, 2020, 2:47 p.m. UTC | #1
On Mon, Mar 23, 2020 at 07:50:08PM +0200, Andy Shevchenko wrote:
> Instead of keeping NULL terminated array switch to use ARRAY_SIZE()
> which helps to further clean up.

Any comments on this?

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/block/zram/zcomp.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
> index 1a8564a79d8d..e78e7a2ccfd5 100644
> --- a/drivers/block/zram/zcomp.c
> +++ b/drivers/block/zram/zcomp.c
> @@ -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,
> -- 
> 2.25.1
>
Andy Shevchenko May 6, 2020, 12:43 p.m. UTC | #2
On Wed, Apr 15, 2020 at 05:47:47PM +0300, Andy Shevchenko wrote:
> On Mon, Mar 23, 2020 at 07:50:08PM +0200, Andy Shevchenko wrote:
> > 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?

> 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  drivers/block/zram/zcomp.c | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
> > index 1a8564a79d8d..e78e7a2ccfd5 100644
> > --- a/drivers/block/zram/zcomp.c
> > +++ b/drivers/block/zram/zcomp.c
> > @@ -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,
> > -- 
> > 2.25.1
> > 
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
>
Minchan Kim May 8, 2020, 5:30 a.m. UTC | #3
On Wed, Apr 15, 2020 at 05:47:47PM +0300, Andy Shevchenko wrote:
> On Mon, Mar 23, 2020 at 07:50:08PM +0200, Andy Shevchenko wrote:
> > Instead of keeping NULL terminated array switch to use ARRAY_SIZE()
> > which helps to further clean up.
> 
> Any comments on this?

Acked-by: Minchan Kim <minchan@kernel.org>

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.

> 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> > ---
> >  drivers/block/zram/zcomp.c | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
> > index 1a8564a79d8d..e78e7a2ccfd5 100644
> > --- a/drivers/block/zram/zcomp.c
> > +++ b/drivers/block/zram/zcomp.c
> > @@ -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,
> > -- 
> > 2.25.1
> > 
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
>
Andy Shevchenko May 8, 2020, 10:08 a.m. UTC | #4
On Thu, May 07, 2020 at 10:30:40PM -0700, Minchan Kim wrote:
> On Wed, Apr 15, 2020 at 05:47:47PM +0300, Andy Shevchenko wrote:
> > On Mon, Mar 23, 2020 at 07:50:08PM +0200, Andy Shevchenko wrote:
> > > Instead of keeping NULL terminated array switch to use ARRAY_SIZE()
> > > which helps to further clean up.
> > 
> > Any comments on this?
> 
> Acked-by: Minchan Kim <minchan@kernel.org>

Thanks!

> 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.
diff mbox series

Patch

diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index 1a8564a79d8d..e78e7a2ccfd5 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -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,