lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <75c11af4-3f5e-4909-a3d3-8feea947d4ea@linaro.org>
Date:   Mon, 4 Dec 2023 14:53:05 +0100
From:   Neil Armstrong <neil.armstrong@...aro.org>
To:     Dan Carpenter <dan.carpenter@...aro.org>,
        Sean Paul <seanpaul@...omium.org>
Cc:     Andrzej Hajda <andrzej.hajda@...el.com>,
        Robert Foss <rfoss@...nel.org>,
        Laurent Pinchart <Laurent.pinchart@...asonboard.com>,
        Jonas Karlman <jonas@...boo.se>,
        Jernej Skrabec <jernej.skrabec@...il.com>,
        Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
        Maxime Ripard <mripard@...nel.org>,
        Thomas Zimmermann <tzimmermann@...e.de>,
        David Airlie <airlied@...il.com>,
        Daniel Vetter <daniel@...ll.ch>,
        Inki Dae <inki.dae@...sung.com>,
        dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
        kernel-janitors@...r.kernel.org
Subject: Re: [PATCH] drm/bridge: nxp-ptn3460: fix i2c_master_send() error
 checking

On 04/12/2023 13:29, Dan Carpenter wrote:
> The i2c_master_send/recv() functions return negative error codes or the
> number of bytes that were able to be sent/received.  This code has
> two problems.  1)  Instead of checking if all the bytes were sent or
> received, it checks that at least one byte was sent or received.
> 2) If there was a partial send/receive then we should return a negative
> error code but this code returns success.
> 
> Fixes: a9fe713d7d45 ("drm/bridge: Add PTN3460 bridge driver")
> Cc: stable@...r.kernel.org
> Signed-off-by: Dan Carpenter <dan.carpenter@...aro.org>
> ---
> This is from static analysis and code review.  It's always a concern
> when you add stricter error handling that something will break.
> 
>   drivers/gpu/drm/bridge/nxp-ptn3460.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/nxp-ptn3460.c b/drivers/gpu/drm/bridge/nxp-ptn3460.c
> index d81920227a8a..9b7eb8c669c1 100644
> --- a/drivers/gpu/drm/bridge/nxp-ptn3460.c
> +++ b/drivers/gpu/drm/bridge/nxp-ptn3460.c
> @@ -56,13 +56,13 @@ static int ptn3460_read_bytes(struct ptn3460_bridge *ptn_bridge, char addr,
>   	ret = i2c_master_send(ptn_bridge->client, &addr, 1);
>   	if (ret <= 0) {
>   		DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
> -		return ret;
> +		return ret ?: -EIO;
>   	}
>   
>   	ret = i2c_master_recv(ptn_bridge->client, buf, len);
> -	if (ret <= 0) {
> +	if (ret != len) {

This is impossible, i2c_transfer_buffer_flags() returns len as-is if no error, so
ret can only be negative or equal to len. The original code is right.

>   		DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret);
> -		return ret;
> +		return ret < 0 ? ret : -EIO;
>   	}
>   
>   	return 0;
> @@ -78,9 +78,9 @@ static int ptn3460_write_byte(struct ptn3460_bridge *ptn_bridge, char addr,
>   	buf[1] = val;
>   
>   	ret = i2c_master_send(ptn_bridge->client, buf, ARRAY_SIZE(buf));
> -	if (ret <= 0) {
> +	if (ret != ARRAY_SIZE(buf)) {

Ditto

>   		DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
> -		return ret;
> +		return ret < 0 ? ret : -EIO;
>   	}
>   
>   	return 0;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ