From patchwork Thu Jul 23 15:46:23 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: UBI: eliminate possible undefined behaviour Date: Thu, 23 Jul 2009 05:46:23 -0000 From: Artem Bityutskiy X-Patchwork-Id: 30138 Message-Id: <1248363983-29596-1-git-send-email-dedekind@infradead.org> To: linux-mtd@lists.infradead.org Cc: Artem Bityutskiy , Phil Carmody From: Phil Carmody The assignment to pos when rb is finally NULL is undefined behaviour. Upon seeing that assignment, GCC may assume that rb is not NULL, and the loop condition ``rb'' may be optimised away. Signed-off-by: Phil Carmody Signed-off-by: Artem Bityutskiy --- drivers/mtd/ubi/ubi.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index 6a5fe96..c290f51 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -579,7 +579,8 @@ void ubi_do_get_volume_info(struct ubi_device *ubi, struct ubi_volume *vol, for (rb = rb_first(root), \ pos = (rb ? container_of(rb, typeof(*pos), member) : NULL); \ rb; \ - rb = rb_next(rb), pos = container_of(rb, typeof(*pos), member)) + rb = rb_next(rb), \ + pos = (rb ? container_of(rb, typeof(*pos), member) : NULL)) /** * ubi_zalloc_vid_hdr - allocate a volume identifier header object.