Message ID | cae6602b2c8789239a3d302b3ffc21f5e09d1189.1696586632.git.hverkuil-cisco@xs4all.nl |
---|---|
State | Accepted |
Commit | f31b2cb85f0ee165d78e1c43f6d69f82cc3b2145 |
Headers | show |
Series | media: fix smatch warnings | expand |
On 06/10/2023 12:08, Hans Verkuil wrote: > Instead of returning an error, goto the mutex unlock at > the end of the function. > > Fixes smatch warning: > > drivers/media/usb/dvb-usb-v2/af9035.c:467 af9035_i2c_master_xfer() warn: inconsistent returns '&d->i2c_mutex'. > Locked on : 326,387 > Unlocked on: 465,467 > > Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Fixes: 7bf744f2de0a ("media: dvb-usb-v2: af9035: Fix null-ptr-deref in af9035_i2c_master_xfer") Regards, Hans > CC: Mauro Carvalho Chehab <mchehab@kernel.org> > --- > drivers/media/usb/dvb-usb-v2/af9035.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c > index 33a2aa8907e6..4eb7dd4599b7 100644 > --- a/drivers/media/usb/dvb-usb-v2/af9035.c > +++ b/drivers/media/usb/dvb-usb-v2/af9035.c > @@ -322,8 +322,10 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, > ret = -EOPNOTSUPP; > } else if ((msg[0].addr == state->af9033_i2c_addr[0]) || > (msg[0].addr == state->af9033_i2c_addr[1])) { > - if (msg[0].len < 3 || msg[1].len < 1) > - return -EOPNOTSUPP; > + if (msg[0].len < 3 || msg[1].len < 1) { > + ret = -EOPNOTSUPP; > + goto unlock; > + } > /* demod access via firmware interface */ > u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | > msg[0].buf[2]; > @@ -383,8 +385,10 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, > ret = -EOPNOTSUPP; > } else if ((msg[0].addr == state->af9033_i2c_addr[0]) || > (msg[0].addr == state->af9033_i2c_addr[1])) { > - if (msg[0].len < 3) > - return -EOPNOTSUPP; > + if (msg[0].len < 3) { > + ret = -EOPNOTSUPP; > + goto unlock; > + } > /* demod access via firmware interface */ > u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | > msg[0].buf[2]; > @@ -459,6 +463,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, > ret = -EOPNOTSUPP; > } > > +unlock: > mutex_unlock(&d->i2c_mutex); > > if (ret < 0)
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c index 33a2aa8907e6..4eb7dd4599b7 100644 --- a/drivers/media/usb/dvb-usb-v2/af9035.c +++ b/drivers/media/usb/dvb-usb-v2/af9035.c @@ -322,8 +322,10 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP; } else if ((msg[0].addr == state->af9033_i2c_addr[0]) || (msg[0].addr == state->af9033_i2c_addr[1])) { - if (msg[0].len < 3 || msg[1].len < 1) - return -EOPNOTSUPP; + if (msg[0].len < 3 || msg[1].len < 1) { + ret = -EOPNOTSUPP; + goto unlock; + } /* demod access via firmware interface */ u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | msg[0].buf[2]; @@ -383,8 +385,10 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP; } else if ((msg[0].addr == state->af9033_i2c_addr[0]) || (msg[0].addr == state->af9033_i2c_addr[1])) { - if (msg[0].len < 3) - return -EOPNOTSUPP; + if (msg[0].len < 3) { + ret = -EOPNOTSUPP; + goto unlock; + } /* demod access via firmware interface */ u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | msg[0].buf[2]; @@ -459,6 +463,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP; } +unlock: mutex_unlock(&d->i2c_mutex); if (ret < 0)
Instead of returning an error, goto the mutex unlock at the end of the function. Fixes smatch warning: drivers/media/usb/dvb-usb-v2/af9035.c:467 af9035_i2c_master_xfer() warn: inconsistent returns '&d->i2c_mutex'. Locked on : 326,387 Unlocked on: 465,467 Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> CC: Mauro Carvalho Chehab <mchehab@kernel.org> --- drivers/media/usb/dvb-usb-v2/af9035.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)