diff mbox series

rbd: silence bogus uninitialized warning in rbd_object_map_update_finish()

Message ID 20191113192954.29732-1-idryomov@gmail.com (mailing list archive)
State New, archived
Headers show
Series rbd: silence bogus uninitialized warning in rbd_object_map_update_finish() | expand

Commit Message

Ilya Dryomov Nov. 13, 2019, 7:29 p.m. UTC
Some versions of gcc (so far 6.3 and 7.4) throw a warning:

  drivers/block/rbd.c: In function 'rbd_object_map_callback':
  drivers/block/rbd.c:2124:21: warning: 'current_state' may be used uninitialized in this function [-Wmaybe-uninitialized]
        (current_state == OBJECT_EXISTS && state == OBJECT_EXISTS_CLEAN))
  drivers/block/rbd.c:2092:23: note: 'current_state' was declared here
    u8 state, new_state, current_state;
                          ^~~~~~~~~~~~~

It's bogus because all current_state accesses are guarded by
has_current_state.

Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
 drivers/block/rbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dongsheng Yang Nov. 14, 2019, 2:12 a.m. UTC | #1
On 11/14/2019 03:29 AM, Ilya Dryomov wrote:
> Some versions of gcc (so far 6.3 and 7.4) throw a warning:
>
>    drivers/block/rbd.c: In function 'rbd_object_map_callback':
>    drivers/block/rbd.c:2124:21: warning: 'current_state' may be used uninitialized in this function [-Wmaybe-uninitialized]
>          (current_state == OBJECT_EXISTS && state == OBJECT_EXISTS_CLEAN))
>    drivers/block/rbd.c:2092:23: note: 'current_state' was declared here
>      u8 state, new_state, current_state;
>                            ^~~~~~~~~~~~~
>
> It's bogus because all current_state accesses are guarded by
> has_current_state.
>
> Reported-by: kbuild test robot <lkp@intel.com>
> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
> ---
>   drivers/block/rbd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index 395410b0d335..2aaa56e4cec9 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -2070,7 +2070,7 @@ static int rbd_object_map_update_finish(struct rbd_obj_request *obj_req,
>   	struct rbd_device *rbd_dev = obj_req->img_request->rbd_dev;
>   	struct ceph_osd_data *osd_data;
>   	u64 objno;
> -	u8 state, new_state, current_state;
> +	u8 state, new_state, uninitialized_var(current_state);
>   	bool has_current_state;
>   	void *p;
>   
Reviewed-by: Dongsheng Yang <dongsheng.yang@easystack.cn>

Thanx
diff mbox series

Patch

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 395410b0d335..2aaa56e4cec9 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2070,7 +2070,7 @@  static int rbd_object_map_update_finish(struct rbd_obj_request *obj_req,
 	struct rbd_device *rbd_dev = obj_req->img_request->rbd_dev;
 	struct ceph_osd_data *osd_data;
 	u64 objno;
-	u8 state, new_state, current_state;
+	u8 state, new_state, uninitialized_var(current_state);
 	bool has_current_state;
 	void *p;