From patchwork Sun Dec 3 05:31:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haoran Liu X-Patchwork-Id: 1871001 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=XvUNJYkq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-i2c+bounces-583-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::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 4Sjb6124Ckz1ySY for ; Sun, 3 Dec 2023 16:32:25 +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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 605EB280F71 for ; Sun, 3 Dec 2023 05:32:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0338110F7; Sun, 3 Dec 2023 05:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="XvUNJYkq" X-Original-To: linux-i2c@vger.kernel.org Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 54FE0FA; Sat, 2 Dec 2023 21:32:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=ahHhTIoYSuW4oEicRP fZHV0EEIBQvulbWrXXGWxCOmM=; b=XvUNJYkqX6ES1MpGQU5tjupJCMhggBgbx9 JsJ844kAK5zlGURHSsHHO2wkH2EssxUt4n1uJvUcYEa7TW3f7BPvg07JuinM6XVJ cyukBIGDrZlB0oei2XvKNq+MIGEw/Wa35Qzu/k753g9njzuMFde2HxQ3UCepH50+ Z5r5U/FOs= Received: from localhost.localdomain (unknown [39.144.190.5]) by zwqz-smtp-mta-g5-4 (Coremail) with SMTP id _____wDH11fPEmxlBd11CA--.4371S2; Sun, 03 Dec 2023 13:32:00 +0800 (CST) From: Haoran Liu To: andi.shyti@kernel.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Haoran Liu Subject: [PATCH] [i2c] robotfuzz-osif: Add error handling for i2c_add_adapter in osif_probe Date: Sat, 2 Dec 2023 21:31:42 -0800 Message-Id: <20231203053142.37453-1-liuhaoran14@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: _____wDH11fPEmxlBd11CA--.4371S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cw4xuryfGFy8AF1DJw1fJFb_yoW8Aw43pw 4DKw4DCryUXwna93ZrJa18XryY93yrGFW7CF9rCws3Zan8JFyqqrWftFyS9a48GrZ7Za13 Xryqv347CF1UAaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zifWr_UUUUU= X-CM-SenderInfo: xolxxtxrud0iqu6rljoofrz/1tbiwhA7glc668iM4AAAsJ Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: This patch introduces error handling for the i2c_add_adapter. This missing error handling was identified through static analysis, revealing that the function did not properly address potential failures of i2c_add_adapter. Previously, such a failure could result in incomplete initialization of the I2C adapter, leading to erratic 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-robotfuzz-osif.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-robotfuzz-osif.c b/drivers/i2c/busses/i2c-robotfuzz-osif.c index 66dfa211e736..0f4d84449050 100644 --- a/drivers/i2c/busses/i2c-robotfuzz-osif.c +++ b/drivers/i2c/busses/i2c-robotfuzz-osif.c @@ -161,7 +161,12 @@ static int osif_probe(struct usb_interface *interface, return ret; } - i2c_add_adapter(&(priv->adapter)); + ret = i2c_add_adapter(&(priv->adapter)); + if (ret) { + dev_err(&interface->dev, "i2c_add_adapter failed: %d\n", ret); + usb_put_dev(priv->usb_dev); + return ret; + } version = le16_to_cpu(priv->usb_dev->descriptor.bcdDevice); dev_info(&interface->dev,