2018-01-12 14:49:55

by Philippe Cornu

[permalink] [raw]
Subject: [PATCH] drm/dsi: Fix improper use of mipi_dsi_device_transfer() return value

The function mipi_dsi_device_transfer() returns the number of transmitted
or received bytes on success or a negative error code on failure.

The functions mipi_dsi_shutdown_peripheral(), mipi_dsi_turn_on_peripheral() &
mipi_dsi_set_maximum_return_packet_size() use improperly this returned
value in case of success: 0 should be returned instead of the number of
transmitted bytes.

Signed-off-by: Philippe Cornu <[email protected]>
---
drivers/gpu/drm/drm_mipi_dsi.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 4b47226b90d4..bc73b7f5b9fc 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -498,8 +498,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
.tx_buf = (u8 [2]) { 0, 0 },
.tx_len = 2,
};
+ int ret = mipi_dsi_device_transfer(dsi, &msg);

- return mipi_dsi_device_transfer(dsi, &msg);
+ return (ret < 0) ? ret : 0;
}
EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);

@@ -517,8 +518,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
.tx_buf = (u8 [2]) { 0, 0 },
.tx_len = 2,
};
+ int ret = mipi_dsi_device_transfer(dsi, &msg);

- return mipi_dsi_device_transfer(dsi, &msg);
+ return (ret < 0) ? ret : 0;
}
EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);

@@ -541,8 +543,9 @@ int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
.tx_len = sizeof(tx),
.tx_buf = tx,
};
+ int ret = mipi_dsi_device_transfer(dsi, &msg);

- return mipi_dsi_device_transfer(dsi, &msg);
+ return (ret < 0) ? ret : 0;
}
EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);

--
2.15.1


2018-01-15 09:12:47

by Andrzej Hajda

[permalink] [raw]
Subject: Re: [PATCH] drm/dsi: Fix improper use of mipi_dsi_device_transfer() return value

On 12.01.2018 15:48, Philippe Cornu wrote:
> The function mipi_dsi_device_transfer() returns the number of transmitted
> or received bytes on success or a negative error code on failure.
>
> The functions mipi_dsi_shutdown_peripheral(), mipi_dsi_turn_on_peripheral() &
> mipi_dsi_set_maximum_return_packet_size() use improperly this returned
> value in case of success: 0 should be returned instead of the number of
> transmitted bytes.
>
> Signed-off-by: Philippe Cornu <[email protected]>

I guess, the best would be to create and use some helper similar to
PTR_ERR_OR_ZERO,
but this is also OK.

Reviewed-by: Andrzej Hajda <[email protected]>

 --
Regards
Andrzej

> ---
> drivers/gpu/drm/drm_mipi_dsi.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
> index 4b47226b90d4..bc73b7f5b9fc 100644
> --- a/drivers/gpu/drm/drm_mipi_dsi.c
> +++ b/drivers/gpu/drm/drm_mipi_dsi.c
> @@ -498,8 +498,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
> .tx_buf = (u8 [2]) { 0, 0 },
> .tx_len = 2,
> };
> + int ret = mipi_dsi_device_transfer(dsi, &msg);
>
> - return mipi_dsi_device_transfer(dsi, &msg);
> + return (ret < 0) ? ret : 0;
> }
> EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
>
> @@ -517,8 +518,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
> .tx_buf = (u8 [2]) { 0, 0 },
> .tx_len = 2,
> };
> + int ret = mipi_dsi_device_transfer(dsi, &msg);
>
> - return mipi_dsi_device_transfer(dsi, &msg);
> + return (ret < 0) ? ret : 0;
> }
> EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
>
> @@ -541,8 +543,9 @@ int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
> .tx_len = sizeof(tx),
> .tx_buf = tx,
> };
> + int ret = mipi_dsi_device_transfer(dsi, &msg);
>
> - return mipi_dsi_device_transfer(dsi, &msg);
> + return (ret < 0) ? ret : 0;
> }
> EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
>


2018-01-15 13:42:45

by Philippe Cornu

[permalink] [raw]
Subject: Re: [PATCH] drm/dsi: Fix improper use of mipi_dsi_device_transfer() return value

Hi Andrzej,

On 01/15/2018 10:12 AM, Andrzej Hajda wrote:
> On 12.01.2018 15:48, Philippe Cornu wrote:
>> The function mipi_dsi_device_transfer() returns the number of transmitted
>> or received bytes on success or a negative error code on failure.
>>
>> The functions mipi_dsi_shutdown_peripheral(), mipi_dsi_turn_on_peripheral() &
>> mipi_dsi_set_maximum_return_packet_size() use improperly this returned
>> value in case of success: 0 should be returned instead of the number of
>> transmitted bytes.
>>
>> Signed-off-by: Philippe Cornu <[email protected]>
>
> I guess, the best would be to create and use some helper similar to
> PTR_ERR_OR_ZERO,
> but this is also OK.
>

Many thanks for your comment and review.

Before sending this patch, I searched for a better way to write these
few lines, including searching for such macros but I did not find
anything (pointers are largely covered but simple integers are not).

If someone has a better solution (with macros or otherwise), I am happy
to learn/implement it.

Many thanks,
Philippe : )

> Reviewed-by: Andrzej Hajda <[email protected]>
>
>  --
> Regards
> Andrzej
>
>> ---
>> drivers/gpu/drm/drm_mipi_dsi.c | 9 ++++++---
>> 1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
>> index 4b47226b90d4..bc73b7f5b9fc 100644
>> --- a/drivers/gpu/drm/drm_mipi_dsi.c
>> +++ b/drivers/gpu/drm/drm_mipi_dsi.c
>> @@ -498,8 +498,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
>> .tx_buf = (u8 [2]) { 0, 0 },
>> .tx_len = 2,
>> };
>> + int ret = mipi_dsi_device_transfer(dsi, &msg);
>>
>> - return mipi_dsi_device_transfer(dsi, &msg);
>> + return (ret < 0) ? ret : 0;
>> }
>> EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
>>
>> @@ -517,8 +518,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
>> .tx_buf = (u8 [2]) { 0, 0 },
>> .tx_len = 2,
>> };
>> + int ret = mipi_dsi_device_transfer(dsi, &msg);
>>
>> - return mipi_dsi_device_transfer(dsi, &msg);
>> + return (ret < 0) ? ret : 0;
>> }
>> EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
>>
>> @@ -541,8 +543,9 @@ int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
>> .tx_len = sizeof(tx),
>> .tx_buf = tx,
>> };
>> + int ret = mipi_dsi_device_transfer(dsi, &msg);
>>
>> - return mipi_dsi_device_transfer(dsi, &msg);
>> + return (ret < 0) ? ret : 0;
>> }
>> EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
>>
>
>

2018-01-16 22:23:23

by Sean Paul

[permalink] [raw]
Subject: Re: [PATCH] drm/dsi: Fix improper use of mipi_dsi_device_transfer() return value

On Mon, Jan 15, 2018 at 10:12:24AM +0100, Andrzej Hajda wrote:
> On 12.01.2018 15:48, Philippe Cornu wrote:
> > The function mipi_dsi_device_transfer() returns the number of transmitted
> > or received bytes on success or a negative error code on failure.
> >
> > The functions mipi_dsi_shutdown_peripheral(), mipi_dsi_turn_on_peripheral() &
> > mipi_dsi_set_maximum_return_packet_size() use improperly this returned
> > value in case of success: 0 should be returned instead of the number of
> > transmitted bytes.
> >
> > Signed-off-by: Philippe Cornu <[email protected]>
>
> I guess, the best would be to create and use some helper similar to
> PTR_ERR_OR_ZERO,
> but this is also OK.
>
> Reviewed-by: Andrzej Hajda <[email protected]>

Applied to drm-misc-next. Thanks for the patch and review

Sean

>
> ?--
> Regards
> Andrzej
>
> > ---
> > drivers/gpu/drm/drm_mipi_dsi.c | 9 ++++++---
> > 1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
> > index 4b47226b90d4..bc73b7f5b9fc 100644
> > --- a/drivers/gpu/drm/drm_mipi_dsi.c
> > +++ b/drivers/gpu/drm/drm_mipi_dsi.c
> > @@ -498,8 +498,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
> > .tx_buf = (u8 [2]) { 0, 0 },
> > .tx_len = 2,
> > };
> > + int ret = mipi_dsi_device_transfer(dsi, &msg);
> >
> > - return mipi_dsi_device_transfer(dsi, &msg);
> > + return (ret < 0) ? ret : 0;
> > }
> > EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
> >
> > @@ -517,8 +518,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
> > .tx_buf = (u8 [2]) { 0, 0 },
> > .tx_len = 2,
> > };
> > + int ret = mipi_dsi_device_transfer(dsi, &msg);
> >
> > - return mipi_dsi_device_transfer(dsi, &msg);
> > + return (ret < 0) ? ret : 0;
> > }
> > EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
> >
> > @@ -541,8 +543,9 @@ int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
> > .tx_len = sizeof(tx),
> > .tx_buf = tx,
> > };
> > + int ret = mipi_dsi_device_transfer(dsi, &msg);
> >
> > - return mipi_dsi_device_transfer(dsi, &msg);
> > + return (ret < 0) ? ret : 0;
> > }
> > EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
> >
>
>

--
Sean Paul, Software Engineer, Google / Chromium OS