xtensa/simdisk: fix error handling in proc_read_simdisk()
PATCH 1/1 xtensa/simdisk: fix error handling in proc_read_simdisk()
The frist simple_read_from_buffer() will change ppos. if ppos >= 1. The second simple_read_from_buffer() will does not work and return 0.
--- arch/xtensa/platforms/iss/simdisk.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
arch/xtensa/platforms/iss/simdisk.c +13 -5
@@ -210,13 +210,21 @@ static ssize_t proc_read_simdisk(struct file *file, char __user *buf, {struct simdisk *dev =pde_data (file_inode (file));const char *s = dev->filename; +char *temp; +if (s) { +ssize_t len =strlen (s); + + temp =kmalloc (len +2 ,GFP_KERNEL ); +if (!temp) +return -ENOMEM ; + +scnprintf (temp, len +2 ,"%s\n" , s);ssize_t n =simple_read_from_buffer (buf, size, ppos, - s,strlen (s)); -if (n <0 ) -return n; - buf += n; - size -= n; + temp,strlen (temp)); + +kfree (temp); +return n; }return simple_read_from_buffer (buf, size, ppos,"\n" ,1 ); }
Signature · 1 line
2.17.1
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Yi,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on next-20220509]
url: https://github.com/intel-lab-lkp/linux/commits/Yi-Yang/xtensa-simdisk-fix-error-handling-in-proc_read_simdisk/20220510-161001 base: ab38272e99730375c5db3db1c4cebf691a0550ab config: xtensa-allyesconfig (https://download.01.org/0day-ci/archive/20220510/[email protected]/config) compiler: xtensa-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/62cd9e58ed970829827bd2bfb24f2515a08fd921
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yi-Yang/xtensa-simdisk-fix-error-handling-in-proc_read_simdisk/20220510-161001 git checkout 62cd9e58ed970829827bd2bfb24f2515a08fd921
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=xtensa SHELL=/bin/bash arch/xtensa/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
arch/xtensa/platforms/iss/simdisk.c: In function 'proc_read_simdisk':
>> arch/xtensa/platforms/iss/simdisk.c:223:17: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
223 | ssize_t n = simple_read_from_buffer(buf, size, ppos,
| ^~~~~~~vim +223 arch/xtensa/platforms/iss/simdisk.c
b6c7e873daf765 Victor Prupis 2008-05-19 207
a69755b187749e Al Viro 2013-03-31 208 static ssize_t proc_read_simdisk(struct file *file, char __user *buf,
a69755b187749e Al Viro 2013-03-31 209 size_t size, loff_t *ppos)
b6c7e873daf765 Victor Prupis 2008-05-19 210 {
359745d78351c6 Muchun Song 2022-01-21 211 struct simdisk *dev = pde_data(file_inode(file));
0757f6159f13dc Geert Uytterhoeven 2013-05-09 212 const char *s = dev->filename;
62cd9e58ed9708 Yi Yang 2022-05-10 213 char *temp;
62cd9e58ed9708 Yi Yang 2022-05-10 214
a69755b187749e Al Viro 2013-03-31 215 if (s) {
62cd9e58ed9708 Yi Yang 2022-05-10 216 ssize_t len = strlen(s);
62cd9e58ed9708 Yi Yang 2022-05-10 217
62cd9e58ed9708 Yi Yang 2022-05-10 218 temp = kmalloc(len + 2, GFP_KERNEL);
62cd9e58ed9708 Yi Yang 2022-05-10 219 if (!temp)
62cd9e58ed9708 Yi Yang 2022-05-10 220 return -ENOMEM;
62cd9e58ed9708 Yi Yang 2022-05-10 221
62cd9e58ed9708 Yi Yang 2022-05-10 222 scnprintf(temp, len + 2, "%s\n", s);
a69755b187749e Al Viro 2013-03-31 @223 ssize_t n = simple_read_from_buffer(buf, size, ppos,
62cd9e58ed9708 Yi Yang 2022-05-10 224 temp, strlen(temp));
62cd9e58ed9708 Yi Yang 2022-05-10 225
62cd9e58ed9708 Yi Yang 2022-05-10 226 kfree(temp);
a69755b187749e Al Viro 2013-03-31 227 return n;
a69755b187749e Al Viro 2013-03-31 228 }
a69755b187749e Al Viro 2013-03-31 229 return simple_read_from_buffer(buf, size, ppos, "\n", 1);
b6c7e873daf765 Victor Prupis 2008-05-19 230 }
b6c7e873daf765 Victor Prupis 2008-05-19 231 Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
Max Filippov
maintainerHi Yi,
Quoted 9 lines · Yi Yang
The frist
simple_read_from_buffer()will change ppos. if ppos >= 1. The secondsimple_read_from_buffer()will does not work and return 0.Fixes a69755b18774 ("xtensa simdisk: switch to proc_create_data()")Signed-off-by Yi Yang <[email protected]>--- arch/xtensa/platforms/iss/simdisk.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
Thank you for the fix. I've rearranged the patch a bit, expanding the commit message and fixing the build warning that it introduced and have posted v2. If there's no objections to it I'll add it to my xtensa tree.
Signature · 2 lines
Thanks. -- Max
Quoted 13 lines · Max Filippov
Hi Yi,
Quoted 9 lines · Yi Yang
The frist
simple_read_from_buffer()will change ppos. if ppos >= 1. The secondsimple_read_from_buffer()will does not work and return 0.Fixes a69755b18774 ("xtensa simdisk: switch to proc_create_data()")Signed-off-by Yi Yang <[email protected]>--- arch/xtensa/platforms/iss/simdisk.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
Quoted 4 lines
Thank you for the fix. I've rearranged the patch a bit, expanding the commit message and fixing the build warning that it introduced and have posted v2. If there's no objections to it I'll add it to my xtensa tree.
The patch is very nice. Thank for you .
Signature · 1 line
Yi