From patchwork Wed Dec 6 15:05:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 174619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4165480vqy; Wed, 6 Dec 2023 07:06:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGP+7yMV4hm6MIxw7NZ3mN9FX1H2C4p+YKkCGsT1EglAE0Eoxp/BzrbZEn/dVUzEiSFWvWs X-Received: by 2002:a17:902:f689:b0:1d0:a146:f879 with SMTP id l9-20020a170902f68900b001d0a146f879mr930979plg.34.1701875160865; Wed, 06 Dec 2023 07:06:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701875160; cv=none; d=google.com; s=arc-20160816; b=xcPuuB9IUVeBJXeEDlY26d1DjlSkCEqUAlzUp9r3kT5WOYKIVp2W9P6fekZ5Sr+mxe i9qvuen58GvbEBWvhu/QdDd4/MPrHJjAxn2KLnQs+TCakygCeYGxEc5ilagfuiDcVMz/ lAOSYSjGPxVsW5JlNtGyK+F/Ut3W71lXoVQJRq8cJC9uxaHy+7VVgk4MhW20qoH9eG7y ysgGZqlxJnYS+xywRfmlDdHDpoDorcL/Aifk6h42c9WtHNzmS7x6NlVVBXM8mHqhM/FS hfzMIlyy8WLrWwSYhBQRBbyLtRA5F0fHN+r22k7/WAslhd7RzrzUB3S1I3qlC2QpxoNv y6Cg== 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=hwMf7u3p+RDwOM148aayiXMLKhs7CLyC1S19yofYD4k=; fh=NBYcvYHc8FPYw2gR2HQKVseiKwF5OXhxV7eDq77cDiE=; b=W12KQOeam84EY8RAFNX6G+kAI/b4XY5R3BbD/u4rNTkhLxoOtFGv0q7Mi/BRywIQtS mDJboIQ8fuVUXn/an5tLZkxdZ9E2crRfGICx52JwOYTui7aqNhzVvxxVVwtDDAlIR8kl xGZ4MzDLb/lP1zKS1g4Ad511o560ad1aymsdeQNOpWZMip8oPf0rHnf7TMn/3vdTGany UyHD1EO4P95IP3KAOOwTx5yfHYcWIWqCZ1PwIlMMuWhnOtOYaUg3Miwt7Uk32e9NtErS FyGezGpoaf6XLKZPsMTg9NMDozxRacZl71cYsTkWYpFKX0O8//qRdJ7xKmsOCWsuYrJi MAOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gbxEfaVs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id s24-20020a634518000000b005be18ddf8b4si26167pga.646.2023.12.06.07.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 07:06:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gbxEfaVs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 301A880A0540; Wed, 6 Dec 2023 07:05:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442295AbjLFPFR (ORCPT + 99 others); Wed, 6 Dec 2023 10:05:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442302AbjLFPFP (ORCPT ); Wed, 6 Dec 2023 10:05:15 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2617CB5 for ; Wed, 6 Dec 2023 07:05:21 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-332fd78fa9dso792693f8f.3 for ; Wed, 06 Dec 2023 07:05:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701875119; x=1702479919; 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=hwMf7u3p+RDwOM148aayiXMLKhs7CLyC1S19yofYD4k=; b=gbxEfaVsmGL+nnmZc76/sZqBIMNdLzVRh0CPgYb27gtd3EQ1SCKi/eYbl4MKhWrd3v qiXO36nUN+QC2fXHViUcjpj3g50gtmrbwS4EfsbTQsASluESePe3PFILigu2lVsGU2rn NhjqK0QuqJ9TaH2QrxzWV6Yi6/tK5jzd8ReEOV5l16yxra76eeu/XcZJsj3i8HzovqIB dYoVxnN8oF3TAN9jID+TMZ5W73VZuukpZjLt8iTGiEiNY7uyn3PqLworGVmhvwRPXIJX Un7cBe2a4ItvFmDXkZ4kcyWGUySEzmTgrEefnc4+DWpJeCjRcHBWuMLMBRwsdh/1s3iN YOEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701875119; x=1702479919; 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=hwMf7u3p+RDwOM148aayiXMLKhs7CLyC1S19yofYD4k=; b=P16b5Dg0/gBDTz2tiq5snCwKSdZJ98rG5ZgMatvI4T0PXKqROIajN4q7j2G6m4cDaD x4jcMx7qqnkLI/GUAqw6mqR3nf45l0q4Idfah2XUCvf3EM2b1t6u+OqMK5sAZxJDzTYg U8NZPM8d4TtVn3Kr5AALEovi32InItYykQQOHH8OqOfk9nXCyQDRIOcTVUiLpSgcXMu0 lsCLAELoc0tcEDdMEQJjMjeNB7W484L7Mz2oXma7S2Lyiudw9o5mec4zL/85pbaniCw5 ISdec6BDD7yTqbjAegvYXxm5l6MsN2EIXbqSnXJKvfCIhVTl1D8C35Z0gWQ01R41/wFX 72oA== X-Gm-Message-State: AOJu0YzZrCOrOlHfT2LiLabYDjS6bQUtxgAgGZl5J/YgrPy/CQ36tDL6 mo7YXNKox5l3usn5i/au6WLjVbVDHycJ7eyZpYs= X-Received: by 2002:a5d:564a:0:b0:333:387b:687a with SMTP id j10-20020a5d564a000000b00333387b687amr280196wrw.199.1701875119471; Wed, 06 Dec 2023 07:05:19 -0800 (PST) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id o14-20020a056000010e00b00333359b522dsm12772792wrx.77.2023.12.06.07.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 07:05:19 -0800 (PST) Date: Wed, 6 Dec 2023 18:05:15 +0300 From: Dan Carpenter To: Dan Carpenter Cc: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] drm/bridge: nxp-ptn3460: simplify some error checking Message-ID: <04242630-42d8-4920-8c67-24ac9db6b3c9@moroto.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 06 Dec 2023 07:05:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784545448540645190 X-GMAIL-MSGID: 1784545448540645190 The i2c_master_send/recv() functions return negative error codes or they return "len" on success. So the error handling here can be written as just normal checks for "if (ret < 0) return ret;". No need to complicate things. Btw, in this code the "len" parameter can never be zero, but even if it were, then I feel like this would still be the best way to write it. Fixes: 914437992876 ("drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking") Signed-off-by: Dan Carpenter --- This is not really a bug fix but I added a Fixes tag because I don't want people to pull my other commit without also applying this. drivers/gpu/drm/bridge/nxp-ptn3460.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/bridge/nxp-ptn3460.c b/drivers/gpu/drm/bridge/nxp-ptn3460.c index 9b7eb8c669c1..7c0076e49953 100644 --- a/drivers/gpu/drm/bridge/nxp-ptn3460.c +++ b/drivers/gpu/drm/bridge/nxp-ptn3460.c @@ -54,15 +54,15 @@ static int ptn3460_read_bytes(struct ptn3460_bridge *ptn_bridge, char addr, int ret; ret = i2c_master_send(ptn_bridge->client, &addr, 1); - if (ret <= 0) { + if (ret < 0) { DRM_ERROR("Failed to send i2c command, ret=%d\n", ret); - return ret ?: -EIO; + return ret; } ret = i2c_master_recv(ptn_bridge->client, buf, len); - if (ret != len) { + if (ret < 0) { DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret); - return ret < 0 ? ret : -EIO; + return ret; } 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 != ARRAY_SIZE(buf)) { + if (ret < 0) { DRM_ERROR("Failed to send i2c command, ret=%d\n", ret); - return ret < 0 ? ret : -EIO; + return ret; } return 0;