Message ID | 0cdc2dce-ca89-451a-9774-1482ab2f4762@moroto.mountain |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2725096vqy; Mon, 4 Dec 2023 04:29:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFe608Qi1lDj4ZBdIyBm9J1IcuRrW+dc4vdGFgRv8qkht1daUfzRH1RBrnJ+Uy6+2ZHXJ4I X-Received: by 2002:a17:90b:224f:b0:286:7f04:23c0 with SMTP id hk15-20020a17090b224f00b002867f0423c0mr2129408pjb.4.1701692958838; Mon, 04 Dec 2023 04:29:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701692958; cv=none; d=google.com; s=arc-20160816; b=L3MCSIZnvxPm8UujMvyv4jNhuh1C/DMnHdKWQwFFBrYWdTQFio8AA7khHGUGj3G5WB +NUQa84oLC660HYonsA43GQKflfhYGtqNJIjVt73CvJUK2il7ou6e9BU9IW5sec66oVJ f46703O/jsuUH/aeXKF/aWbWVHx6IaTd2R0E86Xc6iwmLGtbxWfjkpmf860TqAz0/xJP QoEsaOYCCf4nzKoK+YLvNjwd9SeOxoZOj5SySsPvrsW2E9kSD9Bx8VqVbSM3W85rAojJ ycn1eQQ9kjMj1F4PmkCmDMRvwgX+TVXajgaEQuLv4qJaIok8LXGS8rTY6Dt98cnGi3+U XwfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=MkkECO5iEe8wffVmp+N+jpk0G+DJrLKzEev9h10F0Rg=; fh=rsrnxV+5DIBJ9kzfjfLz+s4FL+bihNurzokkt+UkATY=; b=GD/Oes0v/Wr5batttAYUJNL4ywP88XkwHsPZL1ZtRPB17Zv2Lg+hT9zohmzjw25Tsh OTyP+rFglsBt3CGJe/OJk9AoXK4vTFPTXHAIJIXOR2CpoAu+irzxbFO/rcLoSc9uOsW8 i0ppS8X6UQbNv95qcFjBdnLA8FZV2cSE2OHmnbQbkkRK8JZ4LFSPBYpwlsB+XpWz+1b3 RMz8DgPMY/0wzsB0koODpnbG9f1Ar8NAK9mlhNSKEe70jU9qeDxghHPXiX1i+j/haGze l8IcuTpkdFVUb8KLzUJfEv+5kZmh5yMnzwhgASM3pJP/y3OxAgLlev7xTDyyvv/OHAtt cT4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HZGeiMgy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r17-20020a17090aa09100b002858ed80acfsi10009842pjp.131.2023.12.04.04.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 04:29:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HZGeiMgy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F096F8057D82; Mon, 4 Dec 2023 04:29:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235392AbjLDM3G (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Mon, 4 Dec 2023 07:29:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233019AbjLDM3F (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 4 Dec 2023 07:29:05 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08487D2 for <linux-kernel@vger.kernel.org>; Mon, 4 Dec 2023 04:29:11 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40c0e37cfafso3760105e9.0 for <linux-kernel@vger.kernel.org>; Mon, 04 Dec 2023 04:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701692949; x=1702297749; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=MkkECO5iEe8wffVmp+N+jpk0G+DJrLKzEev9h10F0Rg=; b=HZGeiMgySiUnWJmhgw+zXewpTQZsiLfX69MWrxIehWuO5AFYy+Vzi0fzJI2iS0Z74X w2OeWSyXyslK6/G2dBtuSiUYNmJK33wQo3+o6xBKYzMiWvFpe5a7ZrrhCB2zMdp2LLag M3HJZiGboTgpfqTUxKWMSbqLZwdiq8AIMM5oyb1qHT2pGcA0UUTNZzETY1cgV8w0HcJN vvSyiKvUQJmn2OxOZN5avuc9YrzViCcAS6Mt3oC6EmDC66Xcw5Gz/gvKmfiPs2b/qVVr RlZ2RcVzWBSx/UYZjosP+j/PC9mFjwZwzPsTl8EuBj8JLFR7877jic5Egv1+Yb6bmcQ5 +Znw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701692949; x=1702297749; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MkkECO5iEe8wffVmp+N+jpk0G+DJrLKzEev9h10F0Rg=; b=UmbrLUTewA6PVa7g3N7x3rQh421TGw+D0wWOGSf0vz7VhKo+bXy0UsA1/v/+qdN3UO DkyEzJE0QtARhyPbGGE841J5IR3GEiJ0KWvNrwG5mXwoBdO3oCpQ0McBPgnxdoV5cQTn vQp/A2dmJle8XPf0eRL4SzKzIhTTvWgG1cUBY+aJcC0BpjUZ1Zvsh+KmPVTdZXPIVey5 PbYDHGbLVocIKsR+VDeem0nwwQxyO+G4tKddvZf+J/KiB8CCqDjVBXou4vw6ehZME4Ql Aku3ChKq+vEdBcy/MWEPAR9itrFwG7U1P7z87I8/ubRSgau73Y3F3h14uRA4G95S5LQ7 0wzA== X-Gm-Message-State: AOJu0Yx6ICySx1nQ1z6beELUAGzJEMpdeUDvnnwvI1AeHEqLHIWElbd9 d8KXMdjraATHJoTrBQkr68T2+g== X-Received: by 2002:a7b:c041:0:b0:40b:42d4:3319 with SMTP id u1-20020a7bc041000000b0040b42d43319mr2561709wmc.0.1701692949452; Mon, 04 Dec 2023 04:29:09 -0800 (PST) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id j11-20020a05600c190b00b0040b47c69d08sm18464512wmq.18.2023.12.04.04.29.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 04:29:09 -0800 (PST) Date: Mon, 4 Dec 2023 15:29:00 +0300 From: Dan Carpenter <dan.carpenter@linaro.org> To: Sean Paul <seanpaul@chromium.org> Cc: Andrzej Hajda <andrzej.hajda@intel.com>, Neil Armstrong <neil.armstrong@linaro.org>, 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: [PATCH] drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking Message-ID: <0cdc2dce-ca89-451a-9774-1482ab2f4762@moroto.mountain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 04:29:17 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784354396007113263 X-GMAIL-MSGID: 1784354396007113263 |
Series |
drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking
|
|
Commit Message
Dan Carpenter
Dec. 4, 2023, 12:29 p.m. UTC
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(-)
Comments
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. > 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;
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). regards, dan carpenter
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 >
On Mon, 4 Dec 2023 15:29:00 +0300, 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. > > [...] Applied, thanks! [1/1] drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking https://cgit.freedesktop.org/drm/drm-misc/commit/?id=914437992876 Rob
On Tue, Dec 05, 2023 at 02:48:26PM +0100, Robert Foss wrote: > On Mon, 4 Dec 2023 15:29:00 +0300, 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. > > > > [...] > > Applied, thanks! > > [1/1] drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking > https://cgit.freedesktop.org/drm/drm-misc/commit/?id=914437992876 > Wait. That was unexpected. Neil's review comments were correct. I was planning to send a v2 patch which was just a cleanup. regards, dan carpenter
On Tue, Dec 05, 2023 at 03:04:49PM +0100, Robert Foss wrote: > On Tue, Dec 5, 2023, 15:01 Dan Carpenter <dan.carpenter@linaro.org> wrote: > > > On Tue, Dec 05, 2023 at 02:48:26PM +0100, Robert Foss wrote: > > > On Mon, 4 Dec 2023 15:29:00 +0300, 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. > > > > > > > > [...] > > > > > > Applied, thanks! > > > > > > [1/1] drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking > > > https://cgit.freedesktop.org/drm/drm-misc/commit/?id=914437992876 > > > > > > > Wait. That was unexpected. Neil's review comments were correct. I was > > planning to send a v2 patch which was just a cleanup. > > > > Sorry Dan, I was too quick on the draw. Can you send a fixup and I'll apply > it too? > Sure. I will do that. regards, dan carpenter
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) { 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)) { DRM_ERROR("Failed to send i2c command, ret=%d\n", ret); - return ret; + return ret < 0 ? ret : -EIO; } return 0;