Skip to contentSkip to conversation

cifs: Use min_t() when comparing "size_t" and "unsigned long"

PATCH In review Geert Uytterhoeven 3 participants 4 messages Apr 13, 2014 – May 2, 2014

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 cifs: Use min_t() when comparing "size_t" and "unsigned long"

On 32 bit, size_t is "unsigned int", not "unsigned long", causing the following warning when comparing with PAGE_SIZE, which is always "unsigned long":

fs/cifs/file.c: In function ‘cifs_readdata_to_iov’:
fs/cifs/file.c:2757: warning: comparison of distinct pointer types lacks a cast

Introduced by commit 7f25bba819a38ab7310024a9350655f374707e20 ("cifs_iovec_read: keep iov_iter between the calls of cifs_readdata_to_iov()"), which changed the signedness of "remaining" and the code from min_t() to min().

---
PAGE_SIZE should really be size_t, but that would require lots of changes all over the place.

 fs/cifs/file.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/file.c +1 -1
index 8807442c94dd..8add25538a3b 100644
@@ -2754,7 +2754,7 @@ cifs_readdata_to_iov(struct cifs_readdata *rdata, struct iov_iter *iter)
 
 	for (i = 0; i < rdata->nr_pages; i++) {
 		struct page *page = rdata->pages[i];
-		size_t copy = min(remaining, PAGE_SIZE);
+		size_t copy = min_t(size_t, remaining, PAGE_SIZE);
 		size_t written = copy_page_to_iter(page, 0, copy, iter);
 		remaining -= written;
 		if (written < copy && iov_iter_count(iter) > 0)
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 2/2 mm: Initialize error in shmem_file_aio_read()

mm/shmem.c: In function ‘shmem_file_aio_read’:
mm/shmem.c:1414: warning: ‘error’ may be used uninitialized in this function

If the loop is aborted during the first iteration by one of the two first break statements, error will be uninitialized.

Introduced by commit 6e58e79db8a16222b31fc8da1ca2ac2dccfc4237 ("introduce copy_page_to_iter, kill loop over iovec in generic_file_aio_read()").

---
The code is too complex to see if this is an obvious false positive.

 mm/shmem.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +1 -1
index 8f1a95406bae..9f70e02111c6 100644
@@ -1411,7 +1411,7 @@ static ssize_t shmem_file_aio_read(struct kiocb *iocb,
 	pgoff_t index;
 	unsigned long offset;
 	enum sgp_type sgp = SGP_READ;
-	int error;
+	int error = 0;
 	ssize_t retval;
 	size_t count;
 	loff_t *ppos = &iocb->ki_pos;
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

Re: [PATCH 2/2] mm: Initialize error in shmem_file_aio_read()

Quoted 6 lines · Geert Uytterhoeven

mm/shmem.c: In function ‘shmem_file_aio_read’:
mm/shmem.c:1414: warning: ‘error’ may be used uninitialized in this function

If the loop is aborted during the first iteration by one of the two first break statements, error will be uninitialized.

Quoted 7 lines

Introduced by commit 6e58e79db8a16222b31fc8da1ca2ac2dccfc4237 ("introduce copy_page_to_iter, kill loop over iovec in generic_file_aio_read()").

---
The code is too complex to see if this is an obvious false positive.

Good catch; sadly, it *can* be triggered - read() starting past the EOF will step into it. Applied, will push today.

Reviewed-by on v1 1/2
#3 lore raw
In reply to Geert Uytterhoeven
Quoted 25 lines · On Sun, 13 Apr 2014 20:46:21 +0200 Geert Uytterhoeven <[email protected]>…

On 32 bit, size_t is "unsigned int", not "unsigned long", causing the following warning when comparing with PAGE_SIZE, which is always "unsigned long":

fs/cifs/file.c: In function ‘cifs_readdata_to_iov’:
fs/cifs/file.c:2757: warning: comparison of distinct pointer types lacks a cast

Introduced by commit 7f25bba819a38ab7310024a9350655f374707e20 ("cifs_iovec_read: keep iov_iter between the calls of cifs_readdata_to_iov()"), which changed the signedness of "remaining" and the code from min_t() to min().

---
PAGE_SIZE should really be size_t, but that would require lots of changes all over the place.

 fs/cifs/file.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/file.c +0 -0
index 8807442c94dd..8add25538a3b 100644

fs/cifs/file.c cifs_readdata_to_iov(struct cifs_readdata *rdata, struct iov_iter *iter) · line 2760

Quoted 8 lines
fs/cifs/file.c +1 -1
@@ -2754,7 +2754,7 @@ cifs_readdata_to_iov(struct cifs_readdata *rdata, struct iov_iter *iter)
 
 	for (i = 0; i < rdata->nr_pages; i++) {
 		struct page *page = rdata->pages[i];
-		size_t copy = min(remaining, PAGE_SIZE);
+		size_t copy = min_t(size_t, remaining, PAGE_SIZE);
 		size_t written = copy_page_to_iter(page, 0, copy, iter);
 		remaining -= written;
 		if (written < copy && iov_iter_count(iter) > 0)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>