Skip to content

Commit 6fcc542

Browse files
Boaz HarroshChristoph Hellwig
authored andcommitted
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 <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 82e13c7 commit 6fcc542

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

fs/direct-io.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio)
198198
* L1 cache.
199199
*/
200200
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)
202202
{
203-
int n;
204203
if (dio_pages_present(sdio) == 0) {
205204
int ret;
206205

@@ -209,10 +208,7 @@ static inline struct page *dio_get_page(struct dio *dio,
209208
return ERR_PTR(ret);
210209
BUG_ON(dio_pages_present(sdio) == 0);
211210
}
212-
n = sdio->head++;
213-
*from = n ? 0 : sdio->from;
214-
*to = (n == sdio->tail - 1) ? sdio->to : PAGE_SIZE;
215-
return dio->pages[n];
211+
return dio->pages[sdio->head];
216212
}
217213

218214
/**
@@ -911,11 +907,15 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,
911907
while (sdio->block_in_file < sdio->final_block_in_request) {
912908
struct page *page;
913909
size_t from, to;
914-
page = dio_get_page(dio, sdio, &from, &to);
910+
911+
page = dio_get_page(dio, sdio);
915912
if (IS_ERR(page)) {
916913
ret = PTR_ERR(page);
917914
goto out;
918915
}
916+
from = sdio->head ? 0 : sdio->from;
917+
to = (sdio->head == sdio->tail - 1) ? sdio->to : PAGE_SIZE;
918+
sdio->head++;
919919

920920
while (from < to) {
921921
unsigned this_chunk_bytes; /* # of bytes mapped */

0 commit comments

Comments
 (0)