Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5556225rwd; Mon, 12 Jun 2023 06:47:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6h7xc5K/kP85ZFPo1FqmoLZpzDWeC5O0QF4WHh1xA9I/rh+p466z64Xk+vra+WAhg69acF X-Received: by 2002:a05:6a00:2d16:b0:653:609:7e2b with SMTP id fa22-20020a056a002d1600b0065306097e2bmr11639005pfb.2.1686577663345; Mon, 12 Jun 2023 06:47:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686577663; cv=pass; d=google.com; s=arc-20160816; b=qr3P9z2IUK0i8yysYXIPpEzLDRYDab1d6zmaiwUOXMjqAcQcwubq3/hzSBewfHPl+d L4JXac8FnR5U/xMNImTZ0qlI28xDLM6qyngM1QsNa6S2bfjcIB8R62A32ln8omj04MyP WSz7jUONcJ/bHxRfqSAiD9xYk3Ahv5AdAl4idsUebyjIXpGPPuzfjv7I62iioH6no3U4 nHeNNNkDcAU7PKxw8jK1IoL7HjtLoUMG3D8/HC4oWbEOY4w9mhsE+hui5GCyT+W5GgVR 6sMpCF7KemaPQZWfL0Rn4MdNekVMJSsFczCmE2TV9XIo0BZ0jnHKPJeWgEl5VbHIk1A7 9Peg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=KXY8VQhKkFFOtLbw6Vb87gq/7UAvByz9GX1F+r7VcJk=; b=HOyoWrvSwoHBAPEP7oPsVH3wZXeaI/9NNM3ENiP55CglRwV01xXqIWli1gs/LAr9Pd zI1L3gewamq6MLH5fFgyiECK+uLGUnKY+T4K5h4NCqtyGoquTtssH/Imi9xbC1K9fVRt cVYRqPaoipYXYVFmy5Z5kKp0iQ6pypC03Zd1uoXF9tVcdlPh1YIqlBegkWPcUlBFO8nY XKvOZjNcyC+4D9dtg0fpyv+58D8+FIuqZIr9hReqr2YUib81NgAPdznvEdXhYu8cND0p dgQdOLvzl7hY7CdlbbvBP/il4bHOKU/ljO5XouJiBo0QsUY9es6SdWcXFAsNwKjDdiLf 0JVQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=c3ejRZGb; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z29-20020a63b91d000000b0054b4670f5d8si3342369pge.30.2023.06.12.06.47.29; Mon, 12 Jun 2023 06:47:43 -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=@vivo.com header.s=selector2 header.b=c3ejRZGb; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236587AbjFLNfK (ORCPT + 99 others); Mon, 12 Jun 2023 09:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232135AbjFLNfJ (ORCPT ); Mon, 12 Jun 2023 09:35:09 -0400 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2101.outbound.protection.outlook.com [40.107.215.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 813DDE9; Mon, 12 Jun 2023 06:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZwUgPM8ucJ6Rwpt7b5Im6Zpyi4tJpfAWxHmwLIjPJZD3cVhF08FR1T+fHsKJmtE0dNqoH4PsLIfBs5DK/tWkTpdlz1qCjIVqOampLAVvCAsQWvDGsseqWswRef4btB1VHTCdqs7a5eo585eLRQWbuMgN6OeeoXQ+VGKQ28Lrcq3t3f4vQP6PwQZ5zX3SkqpV6OdnlaAWzUvr7KvpLkunezhEoCIOU9gzbu8lwuIUgciUG5LQH+843wJvuUOGXnmurhCessCRlVWBezL8kiw+TkDlSUa05l/6tn4lQC7Mzl/nW74mGebwWoITotr4qINMCH2v/KDO6wg9juX2GNa/ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KXY8VQhKkFFOtLbw6Vb87gq/7UAvByz9GX1F+r7VcJk=; b=N0V1t/lh/oaQMYxROpl30qg6eIlrjSyfpG32nOf0FN0b61wcIyfVD7YOFsrYpcro+nM3+fNgalaLq+QYoyXYIVCsZwp/d5PceuuozigRWpMkrY6O0gDXzqDFiDcgGGJb7vOFB4PQWCMuw3jArXkwKqCX5T31JDFLtiuYRJudwcLA6b2/1ZuVOYasqfnuj9fk+FRaarIhiNauesMO4d4QfxX2STrQGimHCqQu+Y3tryavrNSkROfUbZX07cb6SQIrpRzIyh7o6/kOn6oliuq2zmzQ/s35Itv20CKNZ81aMe4pQ1cfusa5ZQjbYrG+ZIseCLEXP2LKk7tEbYzhcEvnLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KXY8VQhKkFFOtLbw6Vb87gq/7UAvByz9GX1F+r7VcJk=; b=c3ejRZGbgLllGouUOULdPne0lkP92+fXFzOfrk5kfrx5neY5Bow7ioGCmj80O84zdLaL5j95H/JcL0jS1NWZdyWv6rhULPSQG+hIhVAt3a95tr7BFOFNvTL/EUdyWEXYjbicwmg/2xJr1RPA4Bfr6PuQNGKX1sMTPXkYuubZFTZRtho35Kq/nnH/E/eYxbTP+19Dd+8OEWdp+582qwBSqbX/Pxt7cIyk553DbACOQ1yofCvDtq+G8jhe+mrlxb5aN4Wma+VUPAfdP2WBBONfzJS1b34j2ufnfqQazFm0sKZ5qBtJMcQF7XoLDZ7/13oBeV0TGq67ekugr3Fn2I7ibw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from TYZPR06MB6697.apcprd06.prod.outlook.com (2603:1096:400:451::6) by KL1PR0601MB4177.apcprd06.prod.outlook.com (2603:1096:820:2c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.42; Mon, 12 Jun 2023 13:35:02 +0000 Received: from TYZPR06MB6697.apcprd06.prod.outlook.com ([fe80::f652:a96b:482:409e]) by TYZPR06MB6697.apcprd06.prod.outlook.com ([fe80::f652:a96b:482:409e%5]) with mapi id 15.20.6455.030; Mon, 12 Jun 2023 13:35:02 +0000 From: Lu Hongfei To: Andy Gross , Bjorn Andersson , Konrad Dybcio , linux-arm-msm@vger.kernel.org (open list:ARM/QUALCOMM SUPPORT), linux-kernel@vger.kernel.org (open list) Cc: opensource.kernel@vivo.com, luhongfei@vivo.com Subject: [PATCH v3] soc: qcom: pmic: Fix resource leaks in a device_for_each_child_node() loop Date: Mon, 12 Jun 2023 21:34:52 +0800 Message-Id: <20230612133452.47315-1-luhongfei@vivo.com> X-Mailer: git-send-email 2.39.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TY2PR06CA0013.apcprd06.prod.outlook.com (2603:1096:404:42::25) To TYZPR06MB6697.apcprd06.prod.outlook.com (2603:1096:400:451::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR06MB6697:EE_|KL1PR0601MB4177:EE_ X-MS-Office365-Filtering-Correlation-Id: ee456492-187e-408c-4380-08db6b49d2b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z1FYtHTpMcwxR3nd+6IWdRAfuQ8MHG65AvCXvr5TWGIDg8j2/+fBVzNv68JVAwrqC9lYz/HkmPGSuHmftJtdHkKJ6Kb0aKtGHLLzEF/eTbIlVrsn1X+U6N4edWXAtnkw9acffIuDb3pg9/tZQU/tPPZyWKcZjlzWnHxk5cu0faMLyMIXwyakR4Pkeqpvl8V+XoNWBCMzwGnGPCY0VUK6y+EKHMyUSyZbEYLjVIWFqO7davmT2xHy6K8aM2/EbsNGhbD6sGdztC0GhrqrW7G66+EMxICeElw1U1S1Y6ahWaKDsyoC1Pmdg/Ghyoh2BidZwyv2oezFKD1GtWWfKWiin+lWAodkRi2UGUWO0tTAss4jCqSNwgckTjEQwZOMUjCkx3lZHcXZye02uLO9POdSH7/Ors81+mkGAWL1Nhpb+MelKc7FSwICKIrmjneaHcggw5mJFOEcRHUauztHvDM+gMMnU68Qo2SjhSQZXXJ2HgH5p2QyieifUMHIhFpMCyKZ3FkaYopqzN2kaXeragg7DRNMhc1fLMBjqhI6M8LWVk8S6GN2iRASbU+D8fDoZLAK4AttGv2yPVmT0dp/JyBuszPkeXKU/SdWbClCjyxwo8A/k9LltfdGJeEDElLfjwZ1 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TYZPR06MB6697.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(376002)(396003)(366004)(39860400002)(346002)(451199021)(66476007)(478600001)(66556008)(107886003)(66946007)(316002)(110136005)(4326008)(36756003)(86362001)(83380400001)(26005)(6506007)(1076003)(186003)(6666004)(52116002)(2906002)(8936002)(5660300002)(8676002)(41300700001)(6486002)(6512007)(38100700002)(38350700002)(2616005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CTpY7sKILZ6IQTnGD1gAyjsgt/iOYhWGtxJMag7TRzaDVE5pxOFri8t4Jt55?= =?us-ascii?Q?qf58AQwtKzNf5BLHb82RPKZOs9c3boInDhJSud4EBLYvJ4VtQb/BIUlQ75gd?= =?us-ascii?Q?pIZHXX2TN2d8tlhgCV8Vnvndk/xAQYgASgfLr+N9Lu1WXB9J40YyewKd5sXG?= =?us-ascii?Q?goIOrqQtMB2EL1BvDi3bLqumxMDvVRmOvuwiPyJiyWBuQY3LExLyolzCENdx?= =?us-ascii?Q?Uaj1oB85TSVCLZFkQnH1JOxTDsy3+4LFKoEVydkaJMRL5FhIjSd7wqiU/6W+?= =?us-ascii?Q?JdovgUIeQgVLebnxgVLpkAChNBvT/Dg38tf86tIMZbkhAKtESJFDoZS/yiMq?= =?us-ascii?Q?qC37X+1tXR0Zk0c99tpdcm89+C/0yqkkRRloTDGCJFRqAqiiZH8r3tBqOXLi?= =?us-ascii?Q?pLY4Ykpe5TKrwaolbxiFtQqu5Y/PHDzXooZquUNTIL0T38apgtG3YqxMXOou?= =?us-ascii?Q?tB5B+TiW0eJ4LpyXwPKat4PUBu51P12JS8NLDYr24H6PJt/+ROWk8T3iCbcF?= =?us-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xR9zbDfoS?= =?us-ascii?Q?g6Cd5luSAYQVF6vGqlWcl3q+I0b4qBqbeOw8caaim/TJ4BxG+PrO0ImZope1?= =?us-ascii?Q?bhrQqXexktlaolLeaBkwfISjOJ+xttQ4SdnA48PlHWmn8QrWE6JJYwf/5Vsm?= =?us-ascii?Q?JXwIj3xVNZivirWUAbMMBRsEW/AubTFjUEkXq7QF?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee456492-187e-408c-4380-08db6b49d2b1 X-MS-Exchange-CrossTenant-AuthSource: TYZPR06MB6697.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2023 13:35:02.0066 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HALHv4ZiuGZ2sQEmPpXSulHIfzcFwxhshB746sTYmdnF/OH4v5jQPgkbnZvLCici62jzVrla78BwmBIstLdazw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB4177 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, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 The device_for_each_child_node loop should call fwnode_handle_put() before return in some error cases, which could avoid resource leaks. Let's fix this bug in pmic_glink_altmode_probe. Signed-off-by: Lu Hongfei --- The modifications made compared to the previous version are as follows: 1. Modified the patch title 2. Modified the commit message to make it easier to understand patch's modifications. drivers/soc/qcom/pmic_glink_altmode.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/soc/qcom/pmic_glink_altmode.c b/drivers/soc/qcom/pmic_glink_altmode.c index df48fbea4b68..a7fc6570fa1e 100644 --- a/drivers/soc/qcom/pmic_glink_altmode.c +++ b/drivers/soc/qcom/pmic_glink_altmode.c @@ -395,7 +395,7 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, ret = fwnode_property_read_u32(fwnode, "reg", &port); if (ret < 0) { dev_err(dev, "missing reg property of %pOFn\n", fwnode); - return ret; + goto err_node_put; } if (port >= ARRAY_SIZE(altmode->ports)) { @@ -405,7 +405,8 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, if (altmode->ports[port].altmode) { dev_err(dev, "multiple connector definition for port %u\n", port); - return -EINVAL; + ret = -EINVAL; + goto err_node_put; } alt_port = &altmode->ports[port]; @@ -420,33 +421,37 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, ret = devm_drm_bridge_add(dev, &alt_port->bridge); if (ret) - return ret; + goto err_node_put; alt_port->dp_alt.svid = USB_TYPEC_DP_SID; alt_port->dp_alt.mode = USB_TYPEC_DP_MODE; alt_port->dp_alt.active = 1; alt_port->typec_mux = fwnode_typec_mux_get(fwnode); - if (IS_ERR(alt_port->typec_mux)) - return dev_err_probe(dev, PTR_ERR(alt_port->typec_mux), + if (IS_ERR(alt_port->typec_mux)) { + ret = dev_err_probe(dev, PTR_ERR(alt_port->typec_mux), "failed to acquire mode-switch for port: %d\n", port); + goto err_node_put; + } ret = devm_add_action_or_reset(dev, pmic_glink_altmode_put_mux, alt_port->typec_mux); if (ret) - return ret; + goto err_node_put; alt_port->typec_switch = fwnode_typec_switch_get(fwnode); - if (IS_ERR(alt_port->typec_switch)) - return dev_err_probe(dev, PTR_ERR(alt_port->typec_switch), + if (IS_ERR(alt_port->typec_switch)) { + ret = dev_err_probe(dev, PTR_ERR(alt_port->typec_switch), "failed to acquire orientation-switch for port: %d\n", port); + goto err_node_put; + } ret = devm_add_action_or_reset(dev, pmic_glink_altmode_put_switch, alt_port->typec_switch); if (ret) - return ret; + goto err_node_put; } altmode->client = devm_pmic_glink_register_client(dev, @@ -455,6 +460,10 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, pmic_glink_altmode_pdr_notify, altmode); return PTR_ERR_OR_ZERO(altmode->client); + +err_node_put: + fwnode_handle_put(fwnode); + return ret; } static const struct auxiliary_device_id pmic_glink_altmode_id_table[] = { -- 2.39.0