fs/cachefiles: replace simple_strtoul with kstrtoul in fcull
PATCH 1/6 fs/cachefiles: replace simple_strtoul with kstrtoul in fcull
From: Akhmad Zubairugadzhiev <[email protected]>
Replace deprecated simple_strtoul() with kstrtoul() in cachefiles_daemon_fcull(). The kstrtoul() function provides strict overflow checking and is the recommended replacement.
--- fs/cachefiles/daemon.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
fs/cachefiles/daemon.c +23 -13
@@ -405,22 +405,27 @@ static int cachefiles_daemon_range_error(struct cachefiles_cache *cache,*/ static int cachefiles_daemon_frun (struct cachefiles_cache *cache,char *args) { -unsigned long frun; +unsigned long frun; +int ret; -_enter (",%s" , args); +_enter (",%s" , args); -if (!*args) -return -EINVAL ; +if (!*args) +return -EINVAL ; - frun =simple_strtoul (args, &args,10 ); -if (args[0 ] !='%' || args[1 ] !='\0' ) -return -EINVAL ; + ret =kstrtoul (args,10 , &frun); +if (ret <0 ) +return ret; -if (frun <= cache->fcull_percent || frun >=100 ) -return cachefiles_daemon_range_error (cache, args); + args =strchr (args,'%' ); +if (!args || args[1 ] !='\0' ) +return -EINVAL ; - cache->frun_percent = frun; -return 0 ; +if (frun <= cache->fcull_percent || frun >=100 ) +return cachefiles_daemon_range_error (cache, args); + + cache->frun_percent = frun; +return 0 ; }/*
@@ -430,14 +435,19 @@ static int cachefiles_daemon_frun(struct cachefiles_cache *cache, char *args)static int cachefiles_daemon_fcull (struct cachefiles_cache *cache,char *args) {unsigned long fcull; +int ret;_enter (",%s" , args);if (!*args)return -EINVAL ; - fcull =simple_strtoul (args, &args,10 ); -if (args[0 ] !='%' || args[1 ] !='\0' ) + ret =kstrtoul (args,10 , &fcull); +if (ret <0 ) +return ret; + + args =strchr (args,'%' ); +if (!args || args[1 ] !='\0' )return -EINVAL ;if (fcull <= cache->fstop_percent || fcull >= cache->frun_percent)
Signature · 1 line
2.37.1 (Apple Git-137.1)
PATCH 2/6 fs/cachefiles: replace simple_strtoul with kstrtoul in fstop
From: Akhmad Zubairugadzhiev <[email protected]>
Replace deprecated simple_strtoul() with kstrtoul() in cachefiles_daemon_fstop(). The kstrtoul() function provides strict overflow checking and is the recommended replacement.
--- fs/cachefiles/daemon.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/cachefiles/daemon.c +7 -2
@@ -464,14 +464,19 @@ static int cachefiles_daemon_fcull(struct cachefiles_cache *cache, char *args)static int cachefiles_daemon_fstop (struct cachefiles_cache *cache,char *args) {unsigned long fstop; +int ret;_enter (",%s" , args);if (!*args)return -EINVAL ; - fstop =simple_strtoul (args, &args,10 ); -if (args[0 ] !='%' || args[1 ] !='\0' ) + ret =kstrtoul (args,10 , &fstop); +if (ret <0 ) +return ret; + + args =strchr (args,'%' ); +if (!args || args[1 ] !='\0' )return -EINVAL ;if (fstop >= cache->fcull_percent)
Signature · 1 line
2.37.1 (Apple Git-137.1)
PATCH 3/6 fs/cachefiles: replace simple_strtoul with kstrtoul in brun
In reply to AkhmadFrom: Akhmad Zubairugadzhiev <[email protected]>
Replace deprecated simple_strtoul() with kstrtoul() in cachefiles_daemon_brun(). The kstrtoul() function provides strict overflow checking and is the recommended replacement.
--- fs/cachefiles/daemon.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/cachefiles/daemon.c +7 -2
@@ -493,14 +493,19 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)static int cachefiles_daemon_brun (struct cachefiles_cache *cache,char *args) {unsigned long brun; +int ret;_enter (",%s" , args);if (!*args)return -EINVAL ; - brun =simple_strtoul (args, &args,10 ); -if (args[0 ] !='%' || args[1 ] !='\0' ) + ret =kstrtoul (args,10 , &brun); +if (ret <0 ) +return ret; + + args =strchr (args,'%' ); +if (!args || args[1 ] !='\0' )return -EINVAL ;if (brun <= cache->bcull_percent || brun >=100 )
Signature · 1 line
2.37.1 (Apple Git-137.1)
PATCH 4/6 fs/cachefiles: replace simple_strtoul with kstrtoul in bcull
In reply to AkhmadFrom: Akhmad Zubairugadzhiev <[email protected]>
Replace deprecated simple_strtoul() with kstrtoul() in cachefiles_daemon_bcull(). The kstrtoul() function provides strict overflow checking and is the recommended replacement.
--- fs/cachefiles/daemon.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/cachefiles/daemon.c +7 -2
@@ -522,14 +522,19 @@ static int cachefiles_daemon_brun(struct cachefiles_cache *cache, char *args)static int cachefiles_daemon_bcull (struct cachefiles_cache *cache,char *args) {unsigned long bcull; +int ret;_enter (",%s" , args);if (!*args)return -EINVAL ; - bcull =simple_strtoul (args, &args,10 ); -if (args[0 ] !='%' || args[1 ] !='\0' ) + ret =kstrtoul (args,10 , &bcull); +if (ret <0 ) +return ret; + + args =strchr (args,'%' ); +if (!args || args[1 ] !='\0' )return -EINVAL ;if (bcull <= cache->bstop_percent || bcull >= cache->brun_percent)
Signature · 1 line
2.37.1 (Apple Git-137.1)
David Howells
maintainerRe: [PATCH 4/6] fs/cachefiles: replace simple_strtoul with kstrtoul in bcull
fs/cachefiles/daemon.c static int cachefiles_daemon_brun(struct cachefiles_cache *cache, char *args) · line 534
Quoted 5 lines · Akhmad
fs/cachefiles/daemon.c +3
-2- bcull =simple_strtoul (args, &args,10 ); -if (args[0 ] !='%' || args[1 ] !='\0' ) + ret =kstrtoul (args,10 , &bcull); +if (ret <0 ) +return ret;
Nak. This is not an equivalent piece of code, but will cause EINVAL failures.
static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
{
unsigned long long _res;
unsigned int rv;
s = _parse_integer_fixup_radix(s, &base);
rv = _parse_integer(s, base, &_res);
if (rv & KSTRTOX_OVERFLOW)
return -ERANGE;
if (rv == 0)
return -EINVAL;
s += rv;
if (*s == '\n')
s++;
if (*s)
return -EINVAL; <---- here
*res = _res;
return 0;
}kstrtoul() is *not* a drop-in replacement for simple_strtoul(). You should alter _kstrtoull() to return an end parameter too if you're going to do this. The end parameter is quite important.
David
PATCH 5/6 fs/cachefiles: replace simple_strtoul with kstrtoul in bstop
In reply to AkhmadFrom: Akhmad Zubairugadzhiev <[email protected]>
Replace deprecated simple_strtoul() with kstrtoul() in cachefiles_daemon_bstop(). The kstrtoul() function provides strict overflow checking and is the recommended replacement.
--- fs/cachefiles/daemon.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/cachefiles/daemon.c +7 -2
@@ -551,14 +551,19 @@ static int cachefiles_daemon_bcull(struct cachefiles_cache *cache, char *args)static int cachefiles_daemon_bstop (struct cachefiles_cache *cache,char *args) {unsigned long bstop; +int ret;_enter (",%s" , args);if (!*args)return -EINVAL ; - bstop =simple_strtoul (args, &args,10 ); -if (args[0 ] !='%' || args[1 ] !='\0' ) + ret =kstrtoul (args,10 , &bstop); +if (ret <0 ) +return ret; + + args =strchr (args,'%' ); +if (!args || args[1 ] !='\0' )return -EINVAL ;if (bstop >= cache->bcull_percent)
Signature · 1 line
2.37.1 (Apple Git-137.1)
PATCH 6/6 fs/cachefiles: replace simple_strtoul with kstrtoul in debug
In reply to AkhmadFrom: Akhmad Zubairugadzhiev <[email protected]>
Replace deprecated simple_strtoul() with kstrtoul() in cachefiles_daemon_debug(). The kstrtoul() function provides strict overflow checking and is the recommended replacement. Removed unnecessary manual validation as kstrtoul already validates the entire input string.
--- fs/cachefiles/daemon.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
fs/cachefiles/daemon.c +4 -7
@@ -710,20 +710,17 @@ static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args)static int cachefiles_daemon_debug (struct cachefiles_cache *cache,char *args) {unsigned long mask; +int ret;_enter (",%s" , args); - mask =simple_strtoul (args, &args,0 ); -if (args[0 ] !='\0' ) - goto inval; + ret =kstrtoul (args,0 , &mask); +if (ret <0 ) +return ret; cachefiles_debug = mask;_leave (" = 0" );return 0 ; - -inval: -pr_err ("debug command requires mask\n" ); -return -EINVAL ; }/*
Signature · 1 line
2.37.1 (Apple Git-137.1)
fs/cachefiles/daemon.c static int cachefiles_daemon_range_error(struct cachefiles_cache *cache, · line 408
Quoted 3 lines · Akhmad
{
fs/cachefiles/daemon.c +1
-1-unsigned long frun; +unsigned long frun;
You've changed all the tabs to spaces. Please don't do this.