From patchwork Tue Jul 18 21:40:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 122268 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2033956vqt; Tue, 18 Jul 2023 15:01:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlF3rApzPl8CHs8mNRVJQ3eM1yKFOgLVYjYCOhFl0GQI4Hu2/QWIKarOOiiiDK5RGFQTkZQg X-Received: by 2002:a05:6808:ecb:b0:3a1:b6de:ed54 with SMTP id q11-20020a0568080ecb00b003a1b6deed54mr579025oiv.32.1689717709566; Tue, 18 Jul 2023 15:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689717709; cv=none; d=google.com; s=arc-20160816; b=K0T8GUINE1LEQAbNHWEp5y8idMmQ3fkb6eimjWTRWkYzBMTcO+529bP4PX0DoBcVJZ QUVJ1ZqRfPxVdo5qa/k0Ew7S5iSm9sLdWFwa9By+fh7Hs/kqu6sJ5G/tWU+ylcqDTH6W T5HWFuRZfhl0i41oCVXSH6e3eFyAYOjikvnc5d1f0WQ57wwYfNlAT37OdkV0nNPGftIT I3qB242wi/hq7AM07Ml7Ge+ldzTRZujS23MtdED2O9PSFeO+pnH4QIgg0dvkoXwn7+c2 cJeVMxlxuQuXrEYosCoLkupF1vSCNMIf/vosR2nkKJrr0I62Nr3z7ewNVCJ7STk6gcRB 5Chw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=LyjzMXYuyWxw4amNKCCB8oKlHHFUSzGDu6JLZTk+Yvg=; fh=7qMb7UJJNs6kAe0qny+8uhex1fEr7vtTA4yi+f8s1RQ=; b=BElHcqZKbXLzfRXbSn+IKHdFT6eRbj/1hGCRyjNWeaxC0EplhGXa+oGJ31QetIl5MJ X20nKqhhCFyU56tTOyK31S6XCt83xdOJrNdbbACF7macSEGsGrONB2Np81r5/5RjpORI 3af4a7tne7YV5FwjSLxbeykR+ZDPKAxmjRlxVmU/stSAFzBE93O7ynkFngryMlnrbY+a JqQy0+ctzxMB9EumB4TBCfjXLQGeq8eZzz0o3SHOgbt1gT6uK7maYnkQGvUlHLSOPRyU BL+PNv77dH42QE4GrpP8yQurg3pRIS9EHkoEN2dNk3FSd4RbYqYo9zJrKnFadibPsG2j maMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=e0XBrvaa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u22-20020a63d356000000b0055baed7e7e6si2160936pgi.251.2023.07.18.15.01.36; Tue, 18 Jul 2023 15:01:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=e0XBrvaa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229817AbjGRVkO (ORCPT + 99 others); Tue, 18 Jul 2023 17:40:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbjGRVkM (ORCPT ); Tue, 18 Jul 2023 17:40:12 -0400 Received: from smtp.smtpout.orange.fr (smtp-26.smtpout.orange.fr [80.12.242.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39929198D for ; Tue, 18 Jul 2023 14:40:11 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id LsQRqvLQEm389LsQRqb5o4; Tue, 18 Jul 2023 23:40:09 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1689716409; bh=LyjzMXYuyWxw4amNKCCB8oKlHHFUSzGDu6JLZTk+Yvg=; h=From:To:Cc:Subject:Date; b=e0XBrvaag8BjFsVvA7S/ji74YYT8t9NJTOuIQvKemhdLTIoGO7wFkKE4X0Q/zCbtS Qj3pxge5jplvnbWc7VE+t5mDaA7dEJgWnw2VCC6VSKpaR63EVDxI38ELROa4QzqRzR XR1M1/sphqXX0Wi633UsCUcULod3L3iAGjNBO3/9nKe+gDO+QuR0KTKjOosJOXBKkO GZSwky+XeN/cQt8bwfSOWZ6C92dDfU0goYmV+yFOkTE/5fV79SzMhHkGgUK/DtlN1l 2o9GEz2RypMa9qd3NHJiCo7kmzHeMWyJ2dw0k5brbQxscbgiLSPDtwhhfMQDVYZ5i4 AyvxO1yAKcgDQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 18 Jul 2023 23:40:09 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Heikki Krogerus , Greg Kroah-Hartman , Dmitry Baryshkov , Neil Armstrong Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-usb@vger.kernel.org Subject: [PATCH] usb: typec: nb7vpq904m: Add an error handling path in nb7vpq904m_probe() Date: Tue, 18 Jul 2023 23:40:05 +0200 Message-Id: <9118954765821ea9f1179883602b4eca63e91749.1689716381.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771797437213213836 X-GMAIL-MSGID: 1771797437213213836 In case of error in the nb7vpq904m_probe() probe function, some resources need to be freed, as already done in the remove function. Add the missing error handling path and adjust code accordingly. Fixes: 88d8f3ac9c67 ("usb: typec: add support for the nb7vpq904m Type-C Linear Redriver") Signed-off-by: Christophe JAILLET Reviewed-by: Neil Armstrong Acked-by: Heikki Krogerus --- This changes the order with some devm_ allocated resources. I hope this is fine. At least it is consistent with the remove function. --- drivers/usb/typec/mux/nb7vpq904m.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/usb/typec/mux/nb7vpq904m.c b/drivers/usb/typec/mux/nb7vpq904m.c index 80e580d50129..4d1122d95013 100644 --- a/drivers/usb/typec/mux/nb7vpq904m.c +++ b/drivers/usb/typec/mux/nb7vpq904m.c @@ -463,16 +463,18 @@ static int nb7vpq904m_probe(struct i2c_client *client) ret = nb7vpq904m_register_bridge(nb7); if (ret) - return ret; + goto err_disable_gpio; sw_desc.drvdata = nb7; sw_desc.fwnode = dev->fwnode; sw_desc.set = nb7vpq904m_sw_set; nb7->sw = typec_switch_register(dev, &sw_desc); - if (IS_ERR(nb7->sw)) - return dev_err_probe(dev, PTR_ERR(nb7->sw), - "Error registering typec switch\n"); + if (IS_ERR(nb7->sw)) { + ret = dev_err_probe(dev, PTR_ERR(nb7->sw), + "Error registering typec switch\n"); + goto err_disable_gpio; + } retimer_desc.drvdata = nb7; retimer_desc.fwnode = dev->fwnode; @@ -480,12 +482,21 @@ static int nb7vpq904m_probe(struct i2c_client *client) nb7->retimer = typec_retimer_register(dev, &retimer_desc); if (IS_ERR(nb7->retimer)) { - typec_switch_unregister(nb7->sw); - return dev_err_probe(dev, PTR_ERR(nb7->retimer), - "Error registering typec retimer\n"); + ret = dev_err_probe(dev, PTR_ERR(nb7->retimer), + "Error registering typec retimer\n"); + goto err_switch_unregister; } return 0; + +err_switch_unregister: + typec_switch_unregister(nb7->sw); + +err_disable_gpio: + gpiod_set_value(nb7->enable_gpio, 0); + regulator_disable(nb7->vcc_supply); + + return ret; } static void nb7vpq904m_remove(struct i2c_client *client)