drm/panel: type promotion bug in s6e8aa0_read_mtp_id()

Submitted by Dan Carpenter on July 4, 2018, 9:38 a.m.

Details

Message ID 20180704093807.s3lqsb2v6dg2k43d@kili.mountain
State Accepted
Series "drm/panel: type promotion bug in s6e8aa0_read_mtp_id()"
Commit cd0e0ca69109d025b1a1b6609f70682db62138b0
Headers show

Commit Message

Dan Carpenter July 4, 2018, 9:38 a.m.
The ARRAY_SIZE() macro is type size_t.  If s6e8aa0_dcs_read() returns a
negative error code, then "ret < ARRAY_SIZE(id)" is false because the
negative error code is type promoted to a high positive value.

Fixes: 02051ca06371 ("drm/panel: add S6E8AA0 driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c b/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c
index a188a3959f1a..6ad827b93ae1 100644
--- a/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c
+++ b/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c
@@ -823,7 +823,7 @@  static void s6e8aa0_read_mtp_id(struct s6e8aa0 *ctx)
 	int ret, i;
 
 	ret = s6e8aa0_dcs_read(ctx, 0xd1, id, ARRAY_SIZE(id));
-	if (ret < ARRAY_SIZE(id) || id[0] == 0x00) {
+	if (ret < 0 || ret < ARRAY_SIZE(id) || id[0] == 0x00) {
 		dev_err(ctx->dev, "read id failed\n");
 		ctx->error = -EIO;
 		return;

Comments

Andrzej Hajda July 5, 2018, 10:29 a.m.
On 04.07.2018 11:38, Dan Carpenter wrote:
> The ARRAY_SIZE() macro is type size_t.  If s6e8aa0_dcs_read() returns a
> negative error code, then "ret < ARRAY_SIZE(id)" is false because the
> negative error code is type promoted to a high positive value.
>
> Fixes: 02051ca06371 ("drm/panel: add S6E8AA0 driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c b/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c
> index a188a3959f1a..6ad827b93ae1 100644
> --- a/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c
> +++ b/drivers/gpu/drm/panel/panel-samsung-s6e8aa0.c
> @@ -823,7 +823,7 @@ static void s6e8aa0_read_mtp_id(struct s6e8aa0 *ctx)
>  	int ret, i;
>  
>  	ret = s6e8aa0_dcs_read(ctx, 0xd1, id, ARRAY_SIZE(id));
> -	if (ret < ARRAY_SIZE(id) || id[0] == 0x00) {
> +	if (ret < 0 || ret < ARRAY_SIZE(id) || id[0] == 0x00) {
>  		dev_err(ctx->dev, "read id failed\n");
>  		ctx->error = -EIO;
>  		return;
>
>
>

Thanks for the fix.


Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>

 --
Regards
Andrzej
Thierry Reding July 10, 2018, 11:12 a.m.
On Wed, Jul 04, 2018 at 12:38:09PM +0300, Dan Carpenter wrote:
> The ARRAY_SIZE() macro is type size_t.  If s6e8aa0_dcs_read() returns a
> negative error code, then "ret < ARRAY_SIZE(id)" is false because the
> negative error code is type promoted to a high positive value.
> 
> Fixes: 02051ca06371 ("drm/panel: add S6E8AA0 driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied, thanks.

Thierry