Skip to contentSkip to conversation

FS-Cache: Add missing initialization of ret in cachefiles_write_page()

PATCH In review Geert Uytterhoeven 2 participants 5 messages Nov 11, 2015 – Nov 12, 2015 Cachefiles: fs-cache backend for caching on mounted filesystems

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 FS-Cache: Add missing initialization of ret in cachefiles_write_page()

fs/cachefiles/rdwr.c: In function ‘cachefiles_write_page’:
fs/cachefiles/rdwr.c:882: warning: ‘ret’ may be used uninitialized in this function

If the jump to label "error" is taken, "ret" will indeed be uninitialized, and random stack data may be printed by the debug code.

Fixes 102f4d900c9c8f5e ("FS-Cache: Handle a write to the page immediately beyond the EOF marker")
---
 fs/cachefiles/rdwr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cachefiles/rdwr.c +1 -1
index 7a6b02f727874352..bdd28fe9a7f7195b 100644
@@ -879,7 +879,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
 	loff_t pos, eof;
 	size_t len;
 	void *data;
-	int ret;
+	int ret = 0;
 
 	ASSERT(op != NULL);
 	ASSERT(page != NULL);
Signature · 1 line
1.9.1
maintainer
#1 lore raw

fs/cachefiles/rdwr.c int cachefiles_write_page(struct fscache_storage *op, struct page *page) · line 882

Quoted 2 lines · Geert Uytterhoeven
fs/cachefiles/rdwr.c +1 -1
-	int ret;
+	int ret = 0;

This isn't quite the right solution. The uninitialised error path needs to set -ENOBUFS. Unfortunately, my compiler doesn't show a warning:-/

David

#2 lore raw

Hi David,

Quoted 7 lines · David Howells

fs/cachefiles/rdwr.c int cachefiles_write_page(struct fscache_storage *op, struct page *page) · line 882

Quoted 2 lines · Geert Uytterhoeven
fs/cachefiles/rdwr.c +1 -1
-     int ret;
+     int ret = 0;

This isn't quite the right solution. The uninitialised error path needs to set -ENOBUFS.

That's what your commit 102f4d900c9c8f5e ("FS-Cache: Handle a write to the page immediately beyond the EOF marker") does, and is also in its commit description:

Whilst we're at it, change the triggered assertion in CacheFiles to just return -ENOBUFS instead.

"ret" is used only to print the original error in a debug message.

Quoted 1 line

Unfortunately, my compiler doesn't show a warning:-/

Need old gcc (4.1.2 ;-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

maintainer
#3 lore raw
Quoted 11 lines · Geert Uytterhoeven
Quoted 2 lines

This isn't quite the right solution. The uninitialised error path needs to set -ENOBUFS.

That's what your commit 102f4d900c9c8f5e ("FS-Cache: Handle a write to the page immediately beyond the EOF marker") does, and is also in its commit description:

Whilst we're at it, change the triggered assertion in CacheFiles to just return -ENOBUFS instead.

"ret" is used only to print the original error in a debug message.

I'll adjust your patch to set the default value in ret to be -ENOBUFS instead of 0.

Quoted 3 lines
Quoted 1 line

Unfortunately, my compiler doesn't show a warning:-/

Need old gcc (4.1.2 ;-)

Quite possibly - gcc-5.1 does seem to be a bit lacking in detection of such things.

David

#4 lore raw
Quoted 9 lines · David Howells
Quoted 7 lines · Geert Uytterhoeven
Quoted 2 lines

This isn't quite the right solution. The uninitialised error path needs to set -ENOBUFS.

That's what your commit 102f4d900c9c8f5e ("FS-Cache: Handle a write to the page immediately beyond the EOF marker") does, and is also in its commit description:

Quoted 7 lines
Quoted 4 lines

Whilst we're at it, change the triggered assertion in CacheFiles to just return -ENOBUFS instead.

"ret" is used only to print the original error in a debug message.

I'll adjust your patch to set the default value in ret to be -ENOBUFS instead of 0.

OK. Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds