From: Neil Armstrong <neil.armstrong@linaro.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Sean Paul <seanpaul@chromium.org>,
Andrzej Hajda <andrzej.hajda@intel.com>,
Robert Foss <rfoss@kernel.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Inki Dae <inki.dae@samsung.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking
Date: Tue, 5 Dec 2023 09:30:13 +0100 [thread overview]
Message-ID: <9845c9ea-9121-436f-8185-95119a461127@linaro.org> (raw)
In-Reply-To: <bb28e859-215d-4279-bc7e-f601352d06df@suswa.mountain>
On 04/12/2023 17:59, Dan Carpenter wrote:
> On Mon, Dec 04, 2023 at 02:53:05PM +0100, Neil Armstrong wrote:
>> 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@vger.kernel.org
>>> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.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.
>
> It works, but it's not "right". The <= 0 could be changed to < 0. The
> "len" variable is EDID_LENGTH (128).
So indeed, switching to < 0 is the most reasonable, no need to change the ret value in this case.
Neil
>
> regards,
> dan carpenter
>
next prev parent reply other threads:[~2023-12-05 8:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-04 12:29 Dan Carpenter
2023-12-04 13:53 ` Neil Armstrong
2023-12-04 16:59 ` Dan Carpenter
2023-12-05 8:30 ` Neil Armstrong [this message]
2023-12-05 13:48 ` Robert Foss
2023-12-05 14:00 ` Dan Carpenter
[not found] ` <CAN6tsi6c7ncaiRAiAvrs_GoUMB8v9ciaMvu7s7hnPA0KN0xkWg@mail.gmail.com>
2023-12-05 14:09 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9845c9ea-9121-436f-8185-95119a461127@linaro.org \
--to=neil.armstrong@linaro.org \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=andrzej.hajda@intel.com \
--cc=dan.carpenter@linaro.org \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=inki.dae@samsung.com \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=rfoss@kernel.org \
--cc=seanpaul@chromium.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®