diff options
author | Boaz Harrosh <boaz@plexistor.com> | 2014-07-20 05:09:04 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2014-07-24 06:17:07 -0400 |
commit | 6fcc5420bfb91049a318bb4d88fe471248b5b391 (patch) | |
tree | 7facf80d3bcacbd21131c90721355f7ea0ddb0ee /fs/direct-io.c | |
parent | 82e13c71bc655b6dc7110da4e164079dadb44892 (diff) |
direct-io: fix uninitialized warning in do_direct_IO()
The following warnings:
fs/direct-io.c: In function ‘__blockdev_direct_IO’:
fs/direct-io.c:1011:12: warning: ‘to’ may be used uninitialized in this function [-Wmaybe-uninitialized]
fs/direct-io.c:913:16: note: ‘to’ was declared here
fs/direct-io.c:1011:12: warning: ‘from’ may be used uninitialized in this function [-Wmaybe-uninitialized]
fs/direct-io.c:913:10: note: ‘from’ was declared here
are false positive because dio_get_page() either fails, or sets both
'from' and 'to'.
Paul Bolle said ...
Maybe it's better to move initializing "to" and "from" out of
dio_get_page(). That _might_ make it easier for both the the reader and
the compiler to understand what's going on. Something like this:
Christoph Hellwig said ...
The fix of moving the code definitively looks nicer, while I think
uninitialized_var is horrible wart that won't get anywhere near my code.
Boaz Harrosh: I agree with Christoph and Paul
Signed-off-by: Boaz Harrosh <boaz@plexistor.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/direct-io.c')
-rw-r--r-- | fs/direct-io.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/fs/direct-io.c b/fs/direct-io.c index 98040ba388ac..194d0d122cae 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c | |||
@@ -198,9 +198,8 @@ static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio) | |||
198 | * L1 cache. | 198 | * L1 cache. |
199 | */ | 199 | */ |
200 | static inline struct page *dio_get_page(struct dio *dio, | 200 | static inline struct page *dio_get_page(struct dio *dio, |
201 | struct dio_submit *sdio, size_t *from, size_t *to) | 201 | struct dio_submit *sdio) |
202 | { | 202 | { |
203 | int n; | ||
204 | if (dio_pages_present(sdio) == 0) { | 203 | if (dio_pages_present(sdio) == 0) { |
205 | int ret; | 204 | int ret; |
206 | 205 | ||
@@ -209,10 +208,7 @@ static inline struct page *dio_get_page(struct dio *dio, | |||
209 | return ERR_PTR(ret); | 208 | return ERR_PTR(ret); |
210 | BUG_ON(dio_pages_present(sdio) == 0); | 209 | BUG_ON(dio_pages_present(sdio) == 0); |
211 | } | 210 | } |
212 | n = sdio->head++; | 211 | return dio->pages[sdio->head]; |
213 | *from = n ? 0 : sdio->from; | ||
214 | *to = (n == sdio->tail - 1) ? sdio->to : PAGE_SIZE; | ||
215 | return dio->pages[n]; | ||
216 | } | 212 | } |
217 | 213 | ||
218 | /** | 214 | /** |
@@ -911,11 +907,15 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio, | |||
911 | while (sdio->block_in_file < sdio->final_block_in_request) { | 907 | while (sdio->block_in_file < sdio->final_block_in_request) { |
912 | struct page *page; | 908 | struct page *page; |
913 | size_t from, to; | 909 | size_t from, to; |
914 | page = dio_get_page(dio, sdio, &from, &to); | 910 | |
911 | page = dio_get_page(dio, sdio); | ||
915 | if (IS_ERR(page)) { | 912 | if (IS_ERR(page)) { |
916 | ret = PTR_ERR(page); | 913 | ret = PTR_ERR(page); |
917 | goto out; | 914 | goto out; |
918 | } | 915 | } |
916 | from = sdio->head ? 0 : sdio->from; | ||
917 | to = (sdio->head == sdio->tail - 1) ? sdio->to : PAGE_SIZE; | ||
918 | sdio->head++; | ||
919 | 919 | ||
920 | while (from < to) { | 920 | while (from < to) { |
921 | unsigned this_chunk_bytes; /* # of bytes mapped */ | 921 | unsigned this_chunk_bytes; /* # of bytes mapped */ |