Message ID | 20210226232229.1076199-1-colin.king@canonical.com (mailing list archive) |
---|---|
State | New |
Delegated to: | Sakari Ailus |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1lFmSL-00AfSm-BU; Fri, 26 Feb 2021 23:23:33 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbhBZXXQ (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Fri, 26 Feb 2021 18:23:16 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:34201 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbhBZXXP (ORCPT <rfc822;linux-media@vger.kernel.org>); Fri, 26 Feb 2021 18:23:15 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from <colin.king@canonical.com>) id 1lFmRK-0001eh-2t; Fri, 26 Feb 2021 23:22:30 +0000 From: Colin King <colin.king@canonical.com> To: Sakari Ailus <sakari.ailus@linux.intel.com>, Mauro Carvalho Chehab <mchehab@kernel.org>, Arnd Bergmann <arnd@arndb.de>, Srinivas Kandagatla <srinivas.kandagatla@linaro.org>, linux-media@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: i2c: adp1653: fix error handling from a call to adp1653_get_fault Date: Fri, 26 Feb 2021 23:22:29 +0000 Message-Id: <20210226232229.1076199-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.4 (--) X-LSpam-Report: No, score=-2.4 required=5.0 tests=BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no |
Series |
media: i2c: adp1653: fix error handling from a call to adp1653_get_fault
|
|
Commit Message
Colin King
Feb. 26, 2021, 11:22 p.m. UTC
From: Colin Ian King <colin.king@canonical.com> The error check on rval from the call to adp1653_get_fault currently returns if rval is non-zero. This appears to be incorrect as the following if statement checks for various bit settings in rval so clearly rval is expected to be non-zero at that point. Coverity flagged the if statement up as deadcode. Fix this so the error return path only occurs when rval is negative. Addresses-Coverity: ("Logically dead code") Fixes: 287980e49ffc ("remove lots of IS_ERR_VALUE abuses") Signed-off-by: Colin Ian King <colin.king@canonical.com> --- drivers/media/i2c/adp1653.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Feb 26, 2021 at 11:22:29PM +0000, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > The error check on rval from the call to adp1653_get_fault currently > returns if rval is non-zero. This appears to be incorrect as the > following if statement checks for various bit settings in rval so > clearly rval is expected to be non-zero at that point. Coverity > flagged the if statement up as deadcode. Fix this so the error > return path only occurs when rval is negative. > > Addresses-Coverity: ("Logically dead code") > Fixes: 287980e49ffc ("remove lots of IS_ERR_VALUE abuses") > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > drivers/media/i2c/adp1653.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c > index 522a0b10e415..1a4878385394 100644 > --- a/drivers/media/i2c/adp1653.c > +++ b/drivers/media/i2c/adp1653.c > @@ -170,7 +170,7 @@ static int adp1653_set_ctrl(struct v4l2_ctrl *ctrl) > int rval; > > rval = adp1653_get_fault(flash); > - if (rval) > + if (rval < 0) > return rval; This is good, but all the other callers need to fixed as well: 140 static int adp1653_get_ctrl(struct v4l2_ctrl *ctrl) 141 { 142 struct adp1653_flash *flash = 143 container_of(ctrl->handler, struct adp1653_flash, ctrls); 144 int rval; 145 146 rval = adp1653_get_fault(flash); 147 if (rval) 148 return rval; 149 150 ctrl->cur.val = 0; 151 152 if (flash->fault & ADP1653_REG_FAULT_FLT_SCP) ^^^^^^^^^^^^ flash->fault is the equivalent of "rval" for non-negative returns so this condition can never be true. We should never be returning these weird firmware ADP1653_REG_FAULT_FLT_SCP fault codes to the v4l2 layers. 153 ctrl->cur.val |= V4L2_FLASH_FAULT_SHORT_CIRCUIT; 154 if (flash->fault & ADP1653_REG_FAULT_FLT_OT) 155 ctrl->cur.val |= V4L2_FLASH_FAULT_OVER_TEMPERATURE; 156 if (flash->fault & ADP1653_REG_FAULT_FLT_TMR) 157 ctrl->cur.val |= V4L2_FLASH_FAULT_TIMEOUT; 158 if (flash->fault & ADP1653_REG_FAULT_FLT_OV) 159 ctrl->cur.val |= V4L2_FLASH_FAULT_OVER_VOLTAGE; 160 161 flash->fault = 0; 162 163 return 0; 164 } regards, dan carpenter
Hi Dan, Colin, On Sat, Feb 27, 2021 at 01:17:20PM +0300, Dan Carpenter wrote: > On Fri, Feb 26, 2021 at 11:22:29PM +0000, Colin King wrote: > > From: Colin Ian King <colin.king@canonical.com> > > > > The error check on rval from the call to adp1653_get_fault currently > > returns if rval is non-zero. This appears to be incorrect as the > > following if statement checks for various bit settings in rval so > > clearly rval is expected to be non-zero at that point. Coverity > > flagged the if statement up as deadcode. Fix this so the error > > return path only occurs when rval is negative. > > > > Addresses-Coverity: ("Logically dead code") > > Fixes: 287980e49ffc ("remove lots of IS_ERR_VALUE abuses") > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > > --- > > drivers/media/i2c/adp1653.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c > > index 522a0b10e415..1a4878385394 100644 > > --- a/drivers/media/i2c/adp1653.c > > +++ b/drivers/media/i2c/adp1653.c > > @@ -170,7 +170,7 @@ static int adp1653_set_ctrl(struct v4l2_ctrl *ctrl) > > int rval; > > > > rval = adp1653_get_fault(flash); > > - if (rval) > > + if (rval < 0) > > return rval; > > This is good, but all the other callers need to fixed as well: > > > 140 static int adp1653_get_ctrl(struct v4l2_ctrl *ctrl) > 141 { > 142 struct adp1653_flash *flash = > 143 container_of(ctrl->handler, struct adp1653_flash, ctrls); > 144 int rval; > 145 > 146 rval = adp1653_get_fault(flash); > 147 if (rval) > 148 return rval; > 149 > 150 ctrl->cur.val = 0; > 151 > 152 if (flash->fault & ADP1653_REG_FAULT_FLT_SCP) > ^^^^^^^^^^^^ > flash->fault is the equivalent of "rval" for non-negative returns so > this condition can never be true. We should never be returning these > weird firmware ADP1653_REG_FAULT_FLT_SCP fault codes to the v4l2 layers. I think this could be fixed and cleaned up by always retuning zero on success, and checking for flash->faults while holding the mutex in adp1653_init_device. I could fix that, too, just let me know...
diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c index 522a0b10e415..1a4878385394 100644 --- a/drivers/media/i2c/adp1653.c +++ b/drivers/media/i2c/adp1653.c @@ -170,7 +170,7 @@ static int adp1653_set_ctrl(struct v4l2_ctrl *ctrl) int rval; rval = adp1653_get_fault(flash); - if (rval) + if (rval < 0) return rval; if ((rval & (ADP1653_REG_FAULT_FLT_SCP | ADP1653_REG_FAULT_FLT_OT |