From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boaz Harrosh Subject: [PATCH v3] direct-io: fix uninitialized warning in do_direct_IO() Date: Sun, 20 Jul 2014 12:09:04 +0300 Message-ID: <53CB8730.40607@plexistor.com> References: <1404452632-10912-1-git-send-email-pramod.gurav.etc@gmail.com> <20140713115022.GA6054@infradead.org> <53C6B199.2070606@gmail.com> <20140716175803.GA3631@infradead.org> <1405536124.4357.17.camel@x41> <53C79949.7010201@gmail.com> <53C7AF58.5030807@gmail.com> <1405596599.5735.11.camel@x41> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Christoph Hellwig , Borislav Petkov , Sam Ravnborg , pramod.gurav.etc@gmail.com, Jason Cooper , Markus Mayer , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org To: Paul Bolle , Al Viro Return-path: Received: from mail-we0-f178.google.com ([74.125.82.178]:47332 "EHLO mail-we0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750960AbaGTJJI (ORCPT ); Sun, 20 Jul 2014 05:09:08 -0400 Received: by mail-we0-f178.google.com with SMTP id w61so6253729wes.23 for ; Sun, 20 Jul 2014 02:09:06 -0700 (PDT) In-Reply-To: <1405596599.5735.11.camel@x41> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: =46rom: Boaz Harrosh The following warnings: fs/direct-io.c: In function =E2=80=98__blockdev_direct_IO=E2=80=99: fs/direct-io.c:1011:12: warning: =E2=80=98to=E2=80=99 may be used uni= nitialized in this function [-Wmaybe-uninitialized] fs/direct-io.c:913:16: note: =E2=80=98to=E2=80=99 was declared here fs/direct-io.c:1011:12: warning: =E2=80=98from=E2=80=99 may be used u= ninitialized in this function [-Wmaybe-uninitialized] fs/direct-io.c:913:10: note: =E2=80=98from=E2=80=99 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= =2E Boaz Harrosh: I agree with Christoph and Paul Signed-off-by: Boaz Harrosh --- fs/direct-io.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index 98040ba..194d0d1 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) * L1 cache. */ static inline struct page *dio_get_page(struct dio *dio, - struct dio_submit *sdio, size_t *from, size_t *to) + struct dio_submit *sdio) { - int n; if (dio_pages_present(sdio) =3D=3D 0) { int ret; =20 @@ -209,10 +208,7 @@ static inline struct page *dio_get_page(struct dio= *dio, return ERR_PTR(ret); BUG_ON(dio_pages_present(sdio) =3D=3D 0); } - n =3D sdio->head++; - *from =3D n ? 0 : sdio->from; - *to =3D (n =3D=3D sdio->tail - 1) ? sdio->to : PAGE_SIZE; - return dio->pages[n]; + return dio->pages[sdio->head]; } =20 /** @@ -911,11 +907,15 @@ static int do_direct_IO(struct dio *dio, struct d= io_submit *sdio, while (sdio->block_in_file < sdio->final_block_in_request) { struct page *page; size_t from, to; - page =3D dio_get_page(dio, sdio, &from, &to); + + page =3D dio_get_page(dio, sdio); if (IS_ERR(page)) { ret =3D PTR_ERR(page); goto out; } + from =3D sdio->head ? 0 : sdio->from; + to =3D (sdio->head =3D=3D sdio->tail - 1) ? sdio->to : PAGE_SIZE; + sdio->head++; =20 while (from < to) { unsigned this_chunk_bytes; /* # of bytes mapped */ --=20 1.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel= " in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html