All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] xtensa/simdisk: fix error handling in proc_read_simdisk()
@ 2022-05-10  8:05 Yi Yang
  2022-05-10 13:43 ` kernel test robot
  2022-05-11  9:04 ` Max Filippov
  0 siblings, 2 replies; 4+ messages in thread
From: Yi Yang @ 2022-05-10  8:05 UTC (permalink / raw)
  To: chris, jcmvbkbc, viro; +Cc: linux-xtensa, linux-kernel, axboe, wangweiyang2

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.

Fixes: a69755b18774 ("xtensa simdisk: switch to proc_create_data()")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 arch/xtensa/platforms/iss/simdisk.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/arch/xtensa/platforms/iss/simdisk.c b/arch/xtensa/platforms/iss/simdisk.c
index 0f0e0724397f..618c080c388d 100644
--- a/arch/xtensa/platforms/iss/simdisk.c
+++ b/arch/xtensa/platforms/iss/simdisk.c
@@ -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);
 }
-- 
2.17.1


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

* Re: [PATCH -next] xtensa/simdisk: fix error handling in proc_read_simdisk()
  2022-05-10  8:05 [PATCH -next] xtensa/simdisk: fix error handling in proc_read_simdisk() Yi Yang
@ 2022-05-10 13:43 ` kernel test robot
  2022-05-11  9:04 ` Max Filippov
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2022-05-10 13:43 UTC (permalink / raw)
  To: Yi Yang, chris, jcmvbkbc, viro
  Cc: kbuild-all, linux-xtensa, linux-kernel, axboe, wangweiyang2

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/202205102144.vmTlPCDp-lkp@intel.com/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
Reported-by: kernel test robot <lkp@intel.com>

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  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

* Re: [PATCH -next] xtensa/simdisk: fix error handling in proc_read_simdisk()
  2022-05-10  8:05 [PATCH -next] xtensa/simdisk: fix error handling in proc_read_simdisk() Yi Yang
  2022-05-10 13:43 ` kernel test robot
@ 2022-05-11  9:04 ` Max Filippov
  2022-05-11  9:45   ` yiyang (D)
  1 sibling, 1 reply; 4+ messages in thread
From: Max Filippov @ 2022-05-11  9:04 UTC (permalink / raw)
  To: Yi Yang
  Cc: Chris Zankel, Al Viro, open list:TENSILICA XTENSA PORT (xtensa),
	LKML, Jens Axboe, wangweiyang2

Hi Yi,

On Tue, May 10, 2022 at 1:07 AM Yi Yang <yiyang13@huawei.com> wrote:
>
> 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.
>
> Fixes: a69755b18774 ("xtensa simdisk: switch to proc_create_data()")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
>  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.

-- 
Thanks.
-- Max

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

* Re: [PATCH -next] xtensa/simdisk: fix error handling in proc_read_simdisk()
  2022-05-11  9:04 ` Max Filippov
@ 2022-05-11  9:45   ` yiyang (D)
  0 siblings, 0 replies; 4+ messages in thread
From: yiyang (D) @ 2022-05-11  9:45 UTC (permalink / raw)
  To: Max Filippov
  Cc: Chris Zankel, Al Viro, open list:TENSILICA XTENSA PORT (xtensa),
	LKML, Jens Axboe, wangweiyang2



在 2022/5/11 17:04, Max Filippov 写道:
> Hi Yi,
> 
> On Tue, May 10, 2022 at 1:07 AM Yi Yang <yiyang13@huawei.com> wrote:
>>
>> 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.
>>
>> Fixes: a69755b18774 ("xtensa simdisk: switch to proc_create_data()")
>> Signed-off-by: Yi Yang <yiyang13@huawei.com>
>> ---
>>   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.
> 

The patch is very nice. Thank for you .

-- 
Yi

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

end of thread, other threads:[~2022-05-11  9:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10  8:05 [PATCH -next] xtensa/simdisk: fix error handling in proc_read_simdisk() Yi Yang
2022-05-10 13:43 ` kernel test robot
2022-05-11  9:04 ` Max Filippov
2022-05-11  9:45   ` yiyang (D)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.