linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] media: atomisp: fix the uninitialized use and rename "retvalue"
@ 2021-06-24  3:17 Yizhuo
  2021-06-24  9:03 ` Sakari Ailus
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Yizhuo @ 2021-06-24  3:17 UTC (permalink / raw)
  Cc: Yizhuo, Mauro Carvalho Chehab, Sakari Ailus, Greg Kroah-Hartman,
	Juan Antonio Aldea-Armenteros, linux-media, linux-staging,
	linux-kernel

Inside function mt9m114_detect(), variable "retvalue" could
be uninitialized if mt9m114_read_reg() returns error, however, it
is used in the later if statement, which is potentially unsafe.

The local variable "retvalue" is renamed to "model" to avoid
confusion.

Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
 drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
index f5de81132177..b02a8cd3dde7 100644
--- a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
+++ b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
@@ -1533,16 +1533,20 @@ static struct v4l2_ctrl_config mt9m114_controls[] = {
 static int mt9m114_detect(struct mt9m114_device *dev, struct i2c_client *client)
 {
 	struct i2c_adapter *adapter = client->adapter;
-	u32 retvalue;
+	u32 model;
+	int ret;
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
 		dev_err(&client->dev, "%s: i2c error", __func__);
 		return -ENODEV;
 	}
-	mt9m114_read_reg(client, MISENSOR_16BIT, (u32)MT9M114_PID, &retvalue);
-	dev->real_model_id = retvalue;
+	ret = mt9m114_read_reg(client, MISENSOR_16BIT,
+			       (u32)MT9M114_PID, &model);
+	if (ret)
+		return ret;
+	dev->real_model_id = model;
 
-	if (retvalue != MT9M114_MOD_ID) {
+	if (model != MT9M114_MOD_ID) {
 		dev_err(&client->dev, "%s: failed: client->addr = %x\n",
 			__func__, client->addr);
 		return -ENODEV;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] media: atomisp: fix the uninitialized use and rename "retvalue"
  2021-06-24  3:17 [PATCH v2] media: atomisp: fix the uninitialized use and rename "retvalue" Yizhuo
@ 2021-06-24  9:03 ` Sakari Ailus
  2021-06-24  9:31 ` Dan Carpenter
  2021-06-25  5:38 ` [PATCH v3] " Yizhuo
  2 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2021-06-24  9:03 UTC (permalink / raw)
  To: Yizhuo
  Cc: Mauro Carvalho Chehab, Greg Kroah-Hartman,
	Juan Antonio Aldea-Armenteros, linux-media, linux-staging,
	linux-kernel

On Thu, Jun 24, 2021 at 03:17:17AM +0000, Yizhuo wrote:
> Inside function mt9m114_detect(), variable "retvalue" could
> be uninitialized if mt9m114_read_reg() returns error, however, it
> is used in the later if statement, which is potentially unsafe.
> 
> The local variable "retvalue" is renamed to "model" to avoid
> confusion.
> 
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>
> ---
>  drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
> index f5de81132177..b02a8cd3dde7 100644
> --- a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
> +++ b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
> @@ -1533,16 +1533,20 @@ static struct v4l2_ctrl_config mt9m114_controls[] = {
>  static int mt9m114_detect(struct mt9m114_device *dev, struct i2c_client *client)
>  {
>  	struct i2c_adapter *adapter = client->adapter;
> -	u32 retvalue;
> +	u32 model;
> +	int ret;
>  
>  	if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
>  		dev_err(&client->dev, "%s: i2c error", __func__);
>  		return -ENODEV;
>  	}
> -	mt9m114_read_reg(client, MISENSOR_16BIT, (u32)MT9M114_PID, &retvalue);
> -	dev->real_model_id = retvalue;
> +	ret = mt9m114_read_reg(client, MISENSOR_16BIT,
> +			       (u32)MT9M114_PID, &model);

Thanks for the update.

The cast seems to be there still.

> +	if (ret)
> +		return ret;
> +	dev->real_model_id = model;
>  
> -	if (retvalue != MT9M114_MOD_ID) {
> +	if (model != MT9M114_MOD_ID) {
>  		dev_err(&client->dev, "%s: failed: client->addr = %x\n",
>  			__func__, client->addr);
>  		return -ENODEV;

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] media: atomisp: fix the uninitialized use and rename "retvalue"
  2021-06-24  3:17 [PATCH v2] media: atomisp: fix the uninitialized use and rename "retvalue" Yizhuo
  2021-06-24  9:03 ` Sakari Ailus
@ 2021-06-24  9:31 ` Dan Carpenter
  2021-06-25  5:38 ` [PATCH v3] " Yizhuo
  2 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2021-06-24  9:31 UTC (permalink / raw)
  To: Yizhuo
  Cc: Mauro Carvalho Chehab, Sakari Ailus, Greg Kroah-Hartman,
	Juan Antonio Aldea-Armenteros, linux-media, linux-staging,
	linux-kernel

On Thu, Jun 24, 2021 at 03:17:17AM +0000, Yizhuo wrote:
> Inside function mt9m114_detect(), variable "retvalue" could
> be uninitialized if mt9m114_read_reg() returns error, however, it
> is used in the later if statement, which is potentially unsafe.
> 
> The local variable "retvalue" is renamed to "model" to avoid
> confusion.
> 
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>

Please add a Fixes tag.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3] media: atomisp: fix the uninitialized use and rename "retvalue"
  2021-06-24  3:17 [PATCH v2] media: atomisp: fix the uninitialized use and rename "retvalue" Yizhuo
  2021-06-24  9:03 ` Sakari Ailus
  2021-06-24  9:31 ` Dan Carpenter
@ 2021-06-25  5:38 ` Yizhuo
  2021-07-17 21:50   ` Yizhuo Zhai
  2 siblings, 1 reply; 5+ messages in thread
From: Yizhuo @ 2021-06-25  5:38 UTC (permalink / raw)
  Cc: Yizhuo, Mauro Carvalho Chehab, Sakari Ailus, Greg Kroah-Hartman,
	Juan Antonio Aldea-Armenteros, linux-media, linux-staging,
	linux-kernel

Inside function mt9m114_detect(), variable "retvalue" could
be uninitialized if mt9m114_read_reg() returns error, however, it
is used in the later if statement, which is potentially unsafe.

The local variable "retvalue" is renamed to "model" to avoid
confusion.

Fixes: ad85094 (media / atomisp: fix the uninitialized use of model ID)
Signed-off-by: Yizhuo <yzhai003@ucr.edu>
---
 drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
index f5de81132177..77293579a134 100644
--- a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
+++ b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
@@ -1533,16 +1533,19 @@ static struct v4l2_ctrl_config mt9m114_controls[] = {
 static int mt9m114_detect(struct mt9m114_device *dev, struct i2c_client *client)
 {
 	struct i2c_adapter *adapter = client->adapter;
-	u32 retvalue;
+	u32 model;
+	int ret;
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
 		dev_err(&client->dev, "%s: i2c error", __func__);
 		return -ENODEV;
 	}
-	mt9m114_read_reg(client, MISENSOR_16BIT, (u32)MT9M114_PID, &retvalue);
-	dev->real_model_id = retvalue;
+	ret = mt9m114_read_reg(client, MISENSOR_16BIT, MT9M114_PID, &model);
+	if (ret)
+		return ret;
+	dev->real_model_id = model;
 
-	if (retvalue != MT9M114_MOD_ID) {
+	if (model != MT9M114_MOD_ID) {
 		dev_err(&client->dev, "%s: failed: client->addr = %x\n",
 			__func__, client->addr);
 		return -ENODEV;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] media: atomisp: fix the uninitialized use and rename "retvalue"
  2021-06-25  5:38 ` [PATCH v3] " Yizhuo
@ 2021-07-17 21:50   ` Yizhuo Zhai
  0 siblings, 0 replies; 5+ messages in thread
From: Yizhuo Zhai @ 2021-07-17 21:50 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Sakari Ailus, Greg Kroah-Hartman,
	Juan Antonio Aldea-Armenteros, linux-media, linux-staging,
	linux-kernel

All:
Does the new patch work?


On Thu, Jun 24, 2021 at 10:37 PM Yizhuo <yzhai003@ucr.edu> wrote:
>
> Inside function mt9m114_detect(), variable "retvalue" could
> be uninitialized if mt9m114_read_reg() returns error, however, it
> is used in the later if statement, which is potentially unsafe.
>
> The local variable "retvalue" is renamed to "model" to avoid
> confusion.
>
> Fixes: ad85094 (media / atomisp: fix the uninitialized use of model ID)
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>
> ---
>  drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
> index f5de81132177..77293579a134 100644
> --- a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
> +++ b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c
> @@ -1533,16 +1533,19 @@ static struct v4l2_ctrl_config mt9m114_controls[] = {
>  static int mt9m114_detect(struct mt9m114_device *dev, struct i2c_client *client)
>  {
>         struct i2c_adapter *adapter = client->adapter;
> -       u32 retvalue;
> +       u32 model;
> +       int ret;
>
>         if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
>                 dev_err(&client->dev, "%s: i2c error", __func__);
>                 return -ENODEV;
>         }
> -       mt9m114_read_reg(client, MISENSOR_16BIT, (u32)MT9M114_PID, &retvalue);
> -       dev->real_model_id = retvalue;
> +       ret = mt9m114_read_reg(client, MISENSOR_16BIT, MT9M114_PID, &model);
> +       if (ret)
> +               return ret;
> +       dev->real_model_id = model;
>
> -       if (retvalue != MT9M114_MOD_ID) {
> +       if (model != MT9M114_MOD_ID) {
>                 dev_err(&client->dev, "%s: failed: client->addr = %x\n",
>                         __func__, client->addr);
>                 return -ENODEV;
> --
> 2.17.1
>


-- 
Kind Regards,

Yizhuo Zhai

Computer Science, Graduate Student
University of California, Riverside

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-17 21:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24  3:17 [PATCH v2] media: atomisp: fix the uninitialized use and rename "retvalue" Yizhuo
2021-06-24  9:03 ` Sakari Ailus
2021-06-24  9:31 ` Dan Carpenter
2021-06-25  5:38 ` [PATCH v3] " Yizhuo
2021-07-17 21:50   ` Yizhuo Zhai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).