From patchwork Mon Dec 19 21:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 34781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2622767wrn; Mon, 19 Dec 2022 13:24:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXsGNTtxhXXrFgaSgwkCHSbUsMFNJwbir3jXGG1YwfPtBD4yogzSGFA4z2p1CNIp6DGjinA2 X-Received: by 2002:aa7:8502:0:b0:572:8b7d:f350 with SMTP id v2-20020aa78502000000b005728b7df350mr11800546pfn.26.1671485095110; Mon, 19 Dec 2022 13:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671485095; cv=none; d=google.com; s=arc-20160816; b=0i6Rj9CoJWqvw+ZiSml2ydrAnCfrORuY9qCtv1Pv5kcssgfm935ioQh1VTLHMef6Nx CGdOUqvO1YonNZDxIrGxl220fhY+czmuLupxJo1JwJT6e/geWYmbZZmHdF9w6y2xDnQM 8NTvebTLcxIwwnRK4rCWNs2MYp+wiLfiSkuvkyZkuV2hei6F4ca4MPcBmquitUfakOZ9 zPM6YQQtjIg82nhtlwyavxZ9/HN3fD8HNQkQd9v/lsjGwmEm/jCkTXoxHd0eIULyxljh D39NgCjFsSrDEbZBwTgwT7txn85cHVGXHLf6AwyKTuyTze6ads+JsUCOsVyIgsreb8sH vvOg== 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; bh=3zj24nI+Etr3v22zkr980KOH2HbqGFcwtvuenSrrpF8=; b=L+AobFSli6xOVSyTpHoP16htHwsknHxIg3v2X7MXgTxX85mAoQkBUAyvbj7ubcc2wj K6auVciLKfpqcVRXOBxueiclVb2Xg1i7Q9taTSfa7K1JrRiBKibuz9mhuzMOfjxRw4qr jPeFGZ7onGF16vpG9SPIbeRE0eseg5448o6+27nvns6uAPHDX3D9c1TdiGmpeQcS5137 I38lwz1TVvY7DKQ/gw7JFFfdAxUh07j88TttFeqsjUvyASNQ9fc5wZ/Pv8MYAmSru+mJ S572z7EHlCzjKVNBQ+yyMoLvV/CgKiC/2WBtBJ94gxyb4Xq0STmc06qUDqSr2rREph1h arMA== ARC-Authentication-Results: i=1; mx.google.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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o12-20020a056a0015cc00b00574d1f9bdf2si11629732pfu.213.2022.12.19.13.24.42; Mon, 19 Dec 2022 13:24:55 -0800 (PST) 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; 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 S231401AbiLSVR1 (ORCPT + 99 others); Mon, 19 Dec 2022 16:17:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbiLSVRX (ORCPT ); Mon, 19 Dec 2022 16:17:23 -0500 Received: from smtp.smtpout.orange.fr (smtp-20.smtpout.orange.fr [80.12.242.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5982C12776 for ; Mon, 19 Dec 2022 13:17:20 -0800 (PST) Received: from pop-os.home ([86.243.100.34]) by smtp.orange.fr with ESMTPA id 7NVXpqDedLrOW7NVXpZTjE; Mon, 19 Dec 2022 22:17:17 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 19 Dec 2022 22:17:17 +0100 X-ME-IP: 86.243.100.34 From: Christophe JAILLET To: Will Deacon , Robin Murphy , Joerg Roedel , Eric Auger , Jean-Philippe Brucker , Jonathan Cameron Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev Subject: [PATCH] iommu/arm-smmu-v3: Fix an error handling path in arm_smmu_device_probe() Date: Mon, 19 Dec 2022 22:17:09 +0100 Message-Id: <596b9a44410c67d04599cfd4d6825fa8253c8830.1671484609.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752679155297094054?= X-GMAIL-MSGID: =?utf-8?q?1752679155297094054?= In the arm_smmu_device_probe() probe function, we have the following call chain: arm_smmu_device_probe() --> arm_smmu_init_structures() --> arm_smmu_init_queues() --> iopf_queue_alloc() This memory allocation has to be undone in the error handling path of the probe, as already done in the remove function. While at it, also move a iommu_device_sysfs_remove() call to the newly created error handling path so that error handling is all at the same place. Fixes: 395ad89d11fd ("iommu/arm-smmu-v3: Add stall support for platform devices") Signed-off-by: Christophe JAILLET --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index ab160198edd6..2051b1ed1ff6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3826,22 +3826,27 @@ static int arm_smmu_device_probe(struct platform_device *pdev) /* Reset the device */ ret = arm_smmu_device_reset(smmu, bypass); if (ret) - return ret; + goto err_free_queue; /* And we're up. Go go go! */ ret = iommu_device_sysfs_add(&smmu->iommu, dev, NULL, "smmu3.%pa", &ioaddr); if (ret) - return ret; + goto err_free_queue; ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); if (ret) { dev_err(dev, "Failed to register iommu\n"); - iommu_device_sysfs_remove(&smmu->iommu); - return ret; + goto err_remove_sysfs; } return 0; + +err_remove_sysfs: + iommu_device_sysfs_remove(&smmu->iommu); +err_free_queue: + iopf_queue_free(smmu->evtq.iopf); + return ret; } static int arm_smmu_device_remove(struct platform_device *pdev)