Re: [PATCH v6] staging: atomisp: move null check to earlier point

2020-08-06 Thread Cengiz Can



On August 6, 2020 21:39:21 Greg KH  wrote:


On Thu, Aug 06, 2020 at 09:34:22PM +0300, Cengiz Can wrote:

Hello Andy,

Can I get some feedback on v6 please?



It's been 4 days, in the middle of a merge window, please give people a
chance to catch up on other things...


I wasn't aware of that we're currently in a merge window. Sorry for my 
impatience.




and do not top post please.


Sorry. I was tricked by my mobile email client.



thanks,

greg k-h


Thanks again and I wish a smooth merge window to all maintainers.

Cengiz Can


___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v6] staging: atomisp: move null check to earlier point

2020-08-06 Thread Greg KH
On Thu, Aug 06, 2020 at 09:34:22PM +0300, Cengiz Can wrote:
> Hello Andy,
> 
> Can I get some feedback on v6 please?


It's been 4 days, in the middle of a merge window, please give people a
chance to catch up on other things...

and do not top post please.

thanks,

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v6] staging: atomisp: move null check to earlier point

2020-08-06 Thread Cengiz Can

Hello Andy,

Can I get some feedback on v6 please?

I hope it suits your standards this time.

Thank you

On August 2, 2020 01:02:22 Cengiz Can  wrote:


`find_gmin_subdev()` that returns a pointer to `struct
gmin_subdev` can return NULL.

In `gmin_v2p8_ctrl()` there's a call to this function but the
possibility of a NULL was not checked before its being dereferenced,
i.e.:

 /* Acquired here v */
 struct gmin_subdev *gs = find_gmin_subdev(subdev);

 /*  v--Dereferenced here */
 if (gs->v2p8_gpio >= 0) {
 ...
 }

With this change we're null checking `find_gmin_subdev()` result
and we return an error if that's the case. We also WARN()
for the sake of debugging.

Signed-off-by: Cengiz Can 
Reported-by: Coverity Static Analyzer CID 1465536
Suggested-by: Mauro Carvalho Chehab 
---

Please do note that this change introduces a new return value to
`gmin_v2p8_ctrl()`.

[NEW] - raise a WARN and return -ENODEV if there are no subdevices.
  - return result of `gpio_request` or `gpio_direction_output`.
  - return 0 if GPIO is ON.
  - return results of `regulator_enable` or `regulator_disable`.
  - according to PMIC type, return result of `axp_regulator_set`
or `gmin_i2c_write`.
  - return -EINVAL if unknown PMIC type.

Patch Changelog:
  v4: Fix minor typo in commit message
  v5: Remove typo from email subject
  v6: Remove duplicate Signed-off-by tag

drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 5 -
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c 
b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c

index 0df46a1af5f0..1ad0246764a6 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
@@ -871,6 +871,9 @@ static int gmin_v2p8_ctrl(struct v4l2_subdev *subdev, 
int on)

int ret;
int value;

+   if (WARN_ON(!gs))
+   return -ENODEV;
+
if (gs->v2p8_gpio >= 0) {
pr_info("atomisp_gmin_platform: 2.8v power on GPIO %d\n",
gs->v2p8_gpio);
@@ -881,7 +884,7 @@ static int gmin_v2p8_ctrl(struct v4l2_subdev *subdev, 
int on)

pr_err("V2P8 GPIO initialization failed\n");
}

-   if (!gs || gs->v2p8_on == on)
+   if (gs->v2p8_on == on)
return 0;
gs->v2p8_on = on;

--
2.27.0




___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v6] staging: atomisp: move null check to earlier point

2020-08-01 Thread Cengiz Can
`find_gmin_subdev()` that returns a pointer to `struct
gmin_subdev` can return NULL.

In `gmin_v2p8_ctrl()` there's a call to this function but the
possibility of a NULL was not checked before its being dereferenced,
i.e.:

  /* Acquired here v */
  struct gmin_subdev *gs = find_gmin_subdev(subdev);

  /*  v--Dereferenced here */
  if (gs->v2p8_gpio >= 0) {
  ...
  }

With this change we're null checking `find_gmin_subdev()` result
and we return an error if that's the case. We also WARN()
for the sake of debugging.

Signed-off-by: Cengiz Can 
Reported-by: Coverity Static Analyzer CID 1465536
Suggested-by: Mauro Carvalho Chehab 
---

 Please do note that this change introduces a new return value to
 `gmin_v2p8_ctrl()`.

 [NEW] - raise a WARN and return -ENODEV if there are no subdevices.
   - return result of `gpio_request` or `gpio_direction_output`.
   - return 0 if GPIO is ON.
   - return results of `regulator_enable` or `regulator_disable`.
   - according to PMIC type, return result of `axp_regulator_set`
 or `gmin_i2c_write`.
   - return -EINVAL if unknown PMIC type.

 Patch Changelog:
   v4: Fix minor typo in commit message
   v5: Remove typo from email subject
   v6: Remove duplicate Signed-off-by tag

 drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c 
b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
index 0df46a1af5f0..1ad0246764a6 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
@@ -871,6 +871,9 @@ static int gmin_v2p8_ctrl(struct v4l2_subdev *subdev, int 
on)
int ret;
int value;
 
+   if (WARN_ON(!gs))
+   return -ENODEV;
+
if (gs->v2p8_gpio >= 0) {
pr_info("atomisp_gmin_platform: 2.8v power on GPIO %d\n",
gs->v2p8_gpio);
@@ -881,7 +884,7 @@ static int gmin_v2p8_ctrl(struct v4l2_subdev *subdev, int 
on)
pr_err("V2P8 GPIO initialization failed\n");
}
 
-   if (!gs || gs->v2p8_on == on)
+   if (gs->v2p8_on == on)
return 0;
gs->v2p8_on = on;
 
-- 
2.27.0

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel