diff mbox series

media: atomisp: csi2-bridge: check for negative port values

Message ID 8bc2ab0f-88ac-42f1-876b-147da525b1eb@moroto.mountain
State New
Headers show
Series media: atomisp: csi2-bridge: check for negative port values | expand

Commit Message

Dan Carpenter Aug. 5, 2023, 6:53 a.m. UTC
The atomisp_csi2_get_port() function reads an integer value from the
firmware.  We check for invalid positive values but we should also
check for negatives.

Fixes: 8d28ec7e9145 ("media: atomisp: Add support for v4l2-async sensor registration")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Hans de Goede Aug. 12, 2023, 11:01 a.m. UTC | #1
Hi Dan,

On 8/5/23 08:53, Dan Carpenter wrote:
> The atomisp_csi2_get_port() function reads an integer value from the
> firmware.  We check for invalid positive values but we should also
> check for negatives.
> 
> Fixes: 8d28ec7e9145 ("media: atomisp: Add support for v4l2-async sensor registration")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
> index 46d9f31986c9..0f0ec5d7e49d 100644
> --- a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
> +++ b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
> @@ -626,7 +626,7 @@ static int atomisp_csi2_connect_sensor(const struct atomisp_csi2_sensor_config *
>  			goto err_put_adev;
>  
>  		sensor->port = atomisp_csi2_get_port(adev, clock_num);
> -		if (sensor->port >= ATOMISP_CAMERA_NR_PORTS) {
> +		if (sensor->port < 0 || sensor->port >= ATOMISP_CAMERA_NR_PORTS) {
>  			acpi_handle_err(adev->handle, "Invalid port: %d\n", sensor->port);
>  			ret = -EINVAL;
>  			goto err_put_adev;

Thank you for the fix, this code has been refactored in -next and now it uses sensor->link rather then sensor->port with sensor now being a 'struct ipu_sensor *' and link being a 'u8' so checking for < 0 no longer is necessary.

Regards,

Hans
diff mbox series

Patch

diff --git a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
index 46d9f31986c9..0f0ec5d7e49d 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
@@ -626,7 +626,7 @@  static int atomisp_csi2_connect_sensor(const struct atomisp_csi2_sensor_config *
 			goto err_put_adev;
 
 		sensor->port = atomisp_csi2_get_port(adev, clock_num);
-		if (sensor->port >= ATOMISP_CAMERA_NR_PORTS) {
+		if (sensor->port < 0 || sensor->port >= ATOMISP_CAMERA_NR_PORTS) {
 			acpi_handle_err(adev->handle, "Invalid port: %d\n", sensor->port);
 			ret = -EINVAL;
 			goto err_put_adev;