From patchwork Sun Dec 3 08:49:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haoran Liu X-Patchwork-Id: 1871013 X-Patchwork-Delegate: andi.shyti@kernel.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=a3lRV4bu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-i2c+bounces-584-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SjgV30NlXz1ySY for ; Sun, 3 Dec 2023 19:50:02 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 31F0B1C208BE for ; Sun, 3 Dec 2023 08:49:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C2553232; Sun, 3 Dec 2023 08:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="a3lRV4bu" X-Original-To: linux-i2c@vger.kernel.org Received: from m15.mail.163.com (m15.mail.163.com [45.254.50.220]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8F9F9E8; Sun, 3 Dec 2023 00:49:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=5gnjsR58uLKw7gz+U7 2thLU6153WYL0zgBBSFibHDu8=; b=a3lRV4buP5pEicX3B9gJobyP1seYkpWgIw YCY7oeTJuVxQivao21/ryjqRdjgGhQ3Dabt/4aKbXdT8EN8+D6M66erEQM5/BsRA OMuTyqNiqFehkcyJvM+jZE3oDCy2N59vXWnynLXECUuDnwh9M3m3vXdaBK2lFuab neXIi5gAE= Received: from localhost.localdomain (unknown [39.144.190.5]) by zwqz-smtp-mta-g2-3 (Coremail) with SMTP id _____wDXf_QcQWxlgb0tEg--.8205S2; Sun, 03 Dec 2023 16:49:33 +0800 (CST) From: Haoran Liu To: till@harbaum.org Cc: andi.shyti@kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Haoran Liu Subject: [PATCH] [i2c] tiny-usb: Add error handling in i2c_tiny_usb_probe Date: Sun, 3 Dec 2023 00:49:29 -0800 Message-Id: <20231203084929.38168-1-liuhaoran14@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: _____wDXf_QcQWxlgb0tEg--.8205S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tr1UXr48Kr4rCrWDAF1kKrg_yoW8CF45p3 97K39xCr4UJw1SqrsrXa4IgFy5u3yrK3yjkFyDKwsruan8JF9rtrW3tryS9Fy8Gr97uw4D tryjq343CF1UCF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piWrW5UUUUU= X-CM-SenderInfo: xolxxtxrud0iqu6rljoofrz/1tbiZQQ7gl8ZaX4EJQAAso Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: This patch adds error handling for the i2c_add_adapter. The need for this error handling was identified through static analysis, which revealed that the function did not properly address potential failures of i2c_add_adapter. Previously, a failure in this call could lead to an incomplete initialization of the I2C adapter, causing unpredictable behavior. Although the error addressed by this patch may not occur in the current environment, I still suggest implementing these error handling routines if the function is not highly time-sensitive. As the environment evolves or the code gets reused in different contexts, there's a possibility that these errors might occur. In case you find this addition unnecessary, I completely understand and respect your perspective. My intention was to enhance the robustness of the code, but I acknowledge that practical considerations and current functionality might not warrant this change at this point. Signed-off-by: Haoran Liu --- drivers/i2c/busses/i2c-tiny-usb.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c index 1bffe36c40ad..f165e20fea53 100644 --- a/drivers/i2c/busses/i2c-tiny-usb.c +++ b/drivers/i2c/busses/i2c-tiny-usb.c @@ -264,7 +264,12 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface, dev->adapter.dev.parent = &dev->interface->dev; /* and finally attach to i2c layer */ - i2c_add_adapter(&dev->adapter); + retval = i2c_add_adapter(&dev->adapter); + if (retval) { + dev_err(&interface->dev, "i2c_add_adapter failed: %d\n", + retval); + goto error; + } /* inform user about successful attachment to i2c layer */ dev_info(&dev->adapter.dev, "connected i2c-tiny-usb device\n");