linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: fix local var type
@ 2018-08-23  8:59 Weikang Shi
  2018-08-23 11:13 ` Michal Hocko
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Weikang Shi @ 2018-08-23  8:59 UTC (permalink / raw)
  To: akpm
  Cc: alexander.h.duyck, mhocko, vbabka, mgorman, l.stach,
	vdavydov.dev, linux-mm, linux-kernel, my_email, Weikang Shi

In the seq_hex_dump function,the remaining variable is int, but it receive a type of size_t argument.
So I change the type of remaining

Signed-off-by: Weikang Shi <swkhack@gmail.com>
---
 fs/seq_file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 1dea7a8..d0e8bec 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -847,7 +847,8 @@ void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
 		  bool ascii)
 {
 	const u8 *ptr = buf;
-	int i, linelen, remaining = len;
+	int i, linelen;
+	size_t remaining = len;
 	char *buffer;
 	size_t size;
 	int ret;
-- 
2.7.4


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

* Re: [PATCH] fs: fix local var type
  2018-08-23  8:59 [PATCH] fs: fix local var type Weikang Shi
@ 2018-08-23 11:13 ` Michal Hocko
  2018-08-23 11:23   ` David Laight
  2018-08-23 11:58 ` kbuild test robot
  2018-08-24  5:32 ` kbuild test robot
  2 siblings, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2018-08-23 11:13 UTC (permalink / raw)
  To: Weikang Shi
  Cc: akpm, alexander.h.duyck, vbabka, mgorman, l.stach, vdavydov.dev,
	linux-mm, linux-kernel, my_email

On Thu 23-08-18 01:59:14, Weikang Shi wrote:
> In the seq_hex_dump function,the remaining variable is int, but it receive a type of size_t argument.
> So I change the type of remaining

The changelog should explain _why_ we need this fix. Is any of the code
path overflowing?

Besides that I do not think this fix is complete. What about linelen?

Why do we even need len to be size_t? Why it cannot be int as well. I
strongly doubt we need more than 32b here.
 
> Signed-off-by: Weikang Shi <swkhack@gmail.com>
> ---
>  fs/seq_file.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/seq_file.c b/fs/seq_file.c
> index 1dea7a8..d0e8bec 100644
> --- a/fs/seq_file.c
> +++ b/fs/seq_file.c
> @@ -847,7 +847,8 @@ void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
>  		  bool ascii)
>  {
>  	const u8 *ptr = buf;
> -	int i, linelen, remaining = len;
> +	int i, linelen;
> +	size_t remaining = len;
>  	char *buffer;
>  	size_t size;
>  	int ret;
> -- 
> 2.7.4
> 

-- 
Michal Hocko
SUSE Labs

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

* RE: [PATCH] fs: fix local var type
  2018-08-23 11:13 ` Michal Hocko
@ 2018-08-23 11:23   ` David Laight
  0 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2018-08-23 11:23 UTC (permalink / raw)
  To: 'Michal Hocko', Weikang Shi
  Cc: akpm, alexander.h.duyck, vbabka, mgorman, l.stach, vdavydov.dev,
	linux-mm, linux-kernel, my_email

From: Michal Hocko
> Sent: 23 August 2018 12:14
> 
> On Thu 23-08-18 01:59:14, Weikang Shi wrote:
> > In the seq_hex_dump function,the remaining variable is int, but it receive a type of size_t
> argument.
> > So I change the type of remaining
> 
> The changelog should explain _why_ we need this fix. Is any of the code
> path overflowing?
> 
> Besides that I do not think this fix is complete. What about linelen?
> 
> Why do we even need len to be size_t? Why it cannot be int as well. I
> strongly doubt we need more than 32b here.

Although you may well want 'unsigned int' to avoid the sign extension
instruction that gets added for x86_64 when a signed int is added
to a pointer.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH] fs: fix local var type
  2018-08-23  8:59 [PATCH] fs: fix local var type Weikang Shi
  2018-08-23 11:13 ` Michal Hocko
@ 2018-08-23 11:58 ` kbuild test robot
  2018-08-24  5:32 ` kbuild test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2018-08-23 11:58 UTC (permalink / raw)
  To: Weikang Shi
  Cc: kbuild-all, akpm, alexander.h.duyck, mhocko, vbabka, mgorman,
	l.stach, vdavydov.dev, linux-mm, linux-kernel, my_email,
	Weikang Shi

[-- Attachment #1: Type: text/plain, Size: 4854 bytes --]

Hi Weikang,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.18 next-20180822]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Weikang-Shi/fs-fix-local-var-type/20180823-180758
config: x86_64-randconfig-x009-201833 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   In file included from include/linux/list.h:9:0,
                    from include/linux/wait.h:7,
                    from include/linux/wait_bit.h:8,
                    from include/linux/fs.h:6,
                    from fs/seq_file.c:10:
   fs/seq_file.c: In function 'seq_hex_dump':
   include/linux/kernel.h:845:29: warning: comparison of distinct pointer types lacks a cast
      (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                                ^
   include/linux/kernel.h:859:4: note: in expansion of macro '__typecheck'
      (__typecheck(x, y) && __no_side_effects(x, y))
       ^~~~~~~~~~~
   include/linux/kernel.h:869:24: note: in expansion of macro '__safe_cmp'
     __builtin_choose_expr(__safe_cmp(x, y), \
                           ^~~~~~~~~~
   include/linux/kernel.h:878:19: note: in expansion of macro '__careful_cmp'
    #define min(x, y) __careful_cmp(x, y, <)
                      ^~~~~~~~~~~~~
>> fs/seq_file.c:860:13: note: in expansion of macro 'min'
      linelen = min(remaining, rowsize);
                ^~~

vim +/min +860 fs/seq_file.c

839cc2a9 Tetsuo Handa    2013-11-14  843  
37607102 Andy Shevchenko 2015-09-09  844  /* A complete analogue of print_hex_dump() */
37607102 Andy Shevchenko 2015-09-09  845  void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
37607102 Andy Shevchenko 2015-09-09  846  		  int rowsize, int groupsize, const void *buf, size_t len,
37607102 Andy Shevchenko 2015-09-09  847  		  bool ascii)
37607102 Andy Shevchenko 2015-09-09  848  {
37607102 Andy Shevchenko 2015-09-09  849  	const u8 *ptr = buf;
5f9924ac Weikang Shi     2018-08-23  850  	int i, linelen;
5f9924ac Weikang Shi     2018-08-23  851  	size_t remaining = len;
8b91a318 Andy Shevchenko 2015-11-06  852  	char *buffer;
8b91a318 Andy Shevchenko 2015-11-06  853  	size_t size;
37607102 Andy Shevchenko 2015-09-09  854  	int ret;
37607102 Andy Shevchenko 2015-09-09  855  
37607102 Andy Shevchenko 2015-09-09  856  	if (rowsize != 16 && rowsize != 32)
37607102 Andy Shevchenko 2015-09-09  857  		rowsize = 16;
37607102 Andy Shevchenko 2015-09-09  858  
37607102 Andy Shevchenko 2015-09-09  859  	for (i = 0; i < len && !seq_has_overflowed(m); i += rowsize) {
37607102 Andy Shevchenko 2015-09-09 @860  		linelen = min(remaining, rowsize);
37607102 Andy Shevchenko 2015-09-09  861  		remaining -= rowsize;
37607102 Andy Shevchenko 2015-09-09  862  
37607102 Andy Shevchenko 2015-09-09  863  		switch (prefix_type) {
37607102 Andy Shevchenko 2015-09-09  864  		case DUMP_PREFIX_ADDRESS:
37607102 Andy Shevchenko 2015-09-09  865  			seq_printf(m, "%s%p: ", prefix_str, ptr + i);
37607102 Andy Shevchenko 2015-09-09  866  			break;
37607102 Andy Shevchenko 2015-09-09  867  		case DUMP_PREFIX_OFFSET:
37607102 Andy Shevchenko 2015-09-09  868  			seq_printf(m, "%s%.8x: ", prefix_str, i);
37607102 Andy Shevchenko 2015-09-09  869  			break;
37607102 Andy Shevchenko 2015-09-09  870  		default:
37607102 Andy Shevchenko 2015-09-09  871  			seq_printf(m, "%s", prefix_str);
37607102 Andy Shevchenko 2015-09-09  872  			break;
37607102 Andy Shevchenko 2015-09-09  873  		}
37607102 Andy Shevchenko 2015-09-09  874  
8b91a318 Andy Shevchenko 2015-11-06  875  		size = seq_get_buf(m, &buffer);
37607102 Andy Shevchenko 2015-09-09  876  		ret = hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
8b91a318 Andy Shevchenko 2015-11-06  877  					 buffer, size, ascii);
8b91a318 Andy Shevchenko 2015-11-06  878  		seq_commit(m, ret < size ? ret : -1);
8b91a318 Andy Shevchenko 2015-11-06  879  
37607102 Andy Shevchenko 2015-09-09  880  		seq_putc(m, '\n');
37607102 Andy Shevchenko 2015-09-09  881  	}
37607102 Andy Shevchenko 2015-09-09  882  }
37607102 Andy Shevchenko 2015-09-09  883  EXPORT_SYMBOL(seq_hex_dump);
37607102 Andy Shevchenko 2015-09-09  884  

:::::: The code at line 860 was first introduced by commit
:::::: 37607102c4426cf92aeb5da1b1d9a79ba6d95e3f seq_file: provide an analogue of print_hex_dump()

:::::: TO: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 30949 bytes --]

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

* Re: [PATCH] fs: fix local var type
  2018-08-23  8:59 [PATCH] fs: fix local var type Weikang Shi
  2018-08-23 11:13 ` Michal Hocko
  2018-08-23 11:58 ` kbuild test robot
@ 2018-08-24  5:32 ` kbuild test robot
  2 siblings, 0 replies; 5+ messages in thread
From: kbuild test robot @ 2018-08-24  5:32 UTC (permalink / raw)
  To: Weikang Shi
  Cc: kbuild-all, akpm, alexander.h.duyck, mhocko, vbabka, mgorman,
	l.stach, vdavydov.dev, linux-mm, linux-kernel, my_email,
	Weikang Shi

Hi Weikang,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v4.18 next-20180822]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Weikang-Shi/fs-fix-local-var-type/20180823-180758
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

   fs/seq_file.c:210:21: sparse: expression using sizeof(void)
   fs/seq_file.c:210:21: sparse: expression using sizeof(void)
   fs/seq_file.c:276:13: sparse: expression using sizeof(void)
   fs/seq_file.c:276:13: sparse: expression using sizeof(void)
>> fs/seq_file.c:860:27: sparse: incompatible types in comparison expression (different type sizes)
   fs/seq_file.c:1037:24: sparse: incompatible types in comparison expression (different address spaces)
   fs/seq_file.c:1039:24: sparse: incompatible types in comparison expression (different address spaces)
>> fs/seq_file.c:860:27: sparse: call with no type!
   In file included from include/linux/list.h:9:0,
                    from include/linux/wait.h:7,
                    from include/linux/wait_bit.h:8,
                    from include/linux/fs.h:6,
                    from fs/seq_file.c:10:
   fs/seq_file.c: In function 'seq_hex_dump':
   include/linux/kernel.h:845:29: warning: comparison of distinct pointer types lacks a cast
      (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
                                ^
   include/linux/kernel.h:859:4: note: in expansion of macro '__typecheck'
      (__typecheck(x, y) && __no_side_effects(x, y))
       ^~~~~~~~~~~
   include/linux/kernel.h:869:24: note: in expansion of macro '__safe_cmp'
     __builtin_choose_expr(__safe_cmp(x, y), 23-                        ^~~~~~~~~~
   include/linux/kernel.h:878:19: note: in expansion of macro '__careful_cmp'
    #define min(x, y) __careful_cmp(x, y, <)
                      ^~~~~~~~~~~~~
   fs/seq_file.c:860:13: note: in expansion of macro 'min'
      linelen = min(remaining, rowsize);
                ^~~

vim +860 fs/seq_file.c

839cc2a9 Tetsuo Handa    2013-11-14  843  
37607102 Andy Shevchenko 2015-09-09  844  /* A complete analogue of print_hex_dump() */
37607102 Andy Shevchenko 2015-09-09  845  void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
37607102 Andy Shevchenko 2015-09-09  846  		  int rowsize, int groupsize, const void *buf, size_t len,
37607102 Andy Shevchenko 2015-09-09  847  		  bool ascii)
37607102 Andy Shevchenko 2015-09-09  848  {
37607102 Andy Shevchenko 2015-09-09  849  	const u8 *ptr = buf;
5f9924ac Weikang Shi     2018-08-23  850  	int i, linelen;
5f9924ac Weikang Shi     2018-08-23  851  	size_t remaining = len;
8b91a318 Andy Shevchenko 2015-11-06  852  	char *buffer;
8b91a318 Andy Shevchenko 2015-11-06  853  	size_t size;
37607102 Andy Shevchenko 2015-09-09  854  	int ret;
37607102 Andy Shevchenko 2015-09-09  855  
37607102 Andy Shevchenko 2015-09-09  856  	if (rowsize != 16 && rowsize != 32)
37607102 Andy Shevchenko 2015-09-09  857  		rowsize = 16;
37607102 Andy Shevchenko 2015-09-09  858  
37607102 Andy Shevchenko 2015-09-09  859  	for (i = 0; i < len && !seq_has_overflowed(m); i += rowsize) {
37607102 Andy Shevchenko 2015-09-09 @860  		linelen = min(remaining, rowsize);
37607102 Andy Shevchenko 2015-09-09  861  		remaining -= rowsize;
37607102 Andy Shevchenko 2015-09-09  862  
37607102 Andy Shevchenko 2015-09-09  863  		switch (prefix_type) {
37607102 Andy Shevchenko 2015-09-09  864  		case DUMP_PREFIX_ADDRESS:
37607102 Andy Shevchenko 2015-09-09  865  			seq_printf(m, "%s%p: ", prefix_str, ptr + i);
37607102 Andy Shevchenko 2015-09-09  866  			break;
37607102 Andy Shevchenko 2015-09-09  867  		case DUMP_PREFIX_OFFSET:
37607102 Andy Shevchenko 2015-09-09  868  			seq_printf(m, "%s%.8x: ", prefix_str, i);
37607102 Andy Shevchenko 2015-09-09  869  			break;
37607102 Andy Shevchenko 2015-09-09  870  		default:
37607102 Andy Shevchenko 2015-09-09  871  			seq_printf(m, "%s", prefix_str);
37607102 Andy Shevchenko 2015-09-09  872  			break;
37607102 Andy Shevchenko 2015-09-09  873  		}
37607102 Andy Shevchenko 2015-09-09  874  
8b91a318 Andy Shevchenko 2015-11-06  875  		size = seq_get_buf(m, &buffer);
37607102 Andy Shevchenko 2015-09-09  876  		ret = hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
8b91a318 Andy Shevchenko 2015-11-06  877  					 buffer, size, ascii);
8b91a318 Andy Shevchenko 2015-11-06  878  		seq_commit(m, ret < size ? ret : -1);
8b91a318 Andy Shevchenko 2015-11-06  879  
37607102 Andy Shevchenko 2015-09-09  880  		seq_putc(m, '\n');
37607102 Andy Shevchenko 2015-09-09  881  	}
37607102 Andy Shevchenko 2015-09-09  882  }
37607102 Andy Shevchenko 2015-09-09  883  EXPORT_SYMBOL(seq_hex_dump);
37607102 Andy Shevchenko 2015-09-09  884  

:::::: The code at line 860 was first introduced by commit
:::::: 37607102c4426cf92aeb5da1b1d9a79ba6d95e3f seq_file: provide an analogue of print_hex_dump()

:::::: TO: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

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

end of thread, other threads:[~2018-08-24  5:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-23  8:59 [PATCH] fs: fix local var type Weikang Shi
2018-08-23 11:13 ` Michal Hocko
2018-08-23 11:23   ` David Laight
2018-08-23 11:58 ` kbuild test robot
2018-08-24  5:32 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).