From patchwork Mon May 4 11:12:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 214700 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8E4CC3A5A9 for ; Mon, 4 May 2020 11:21:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A694520721 for ; Mon, 4 May 2020 11:21:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727786AbgEDLVo (ORCPT ); Mon, 4 May 2020 07:21:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726445AbgEDLVo (ORCPT ); Mon, 4 May 2020 07:21:44 -0400 X-Greylist: delayed 421 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 04 May 2020 04:21:44 PDT Received: from mailout2.hostsharing.net (mailout2.hostsharing.net [IPv6:2a01:37:3000::53df:4ee9:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02049C061A0E for ; Mon, 4 May 2020 04:21:44 -0700 (PDT) Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout2.hostsharing.net (Postfix) with ESMTPS id 53C8E10189AD9; Mon, 4 May 2020 13:14:42 +0200 (CEST) Received: from localhost (unknown [87.130.102.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 1A23A60F2900; Mon, 4 May 2020 13:14:42 +0200 (CEST) X-Mailbox-Line: From 497cc38ae2beb7900ae05a1463eb83ff96e2770e Mon Sep 17 00:00:00 2001 Message-Id: <497cc38ae2beb7900ae05a1463eb83ff96e2770e.1588590210.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Mon, 4 May 2020 13:12:01 +0200 Subject: [PATCH 1/5] spi: amd: Fix duplicate iounmap in error path To: Mark Brown , "Sanjay R Mehta" Cc: linux-spi@vger.kernel.org Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The AMD SPI driver uses devm_ioremap_resource() to map its registers, so they're automatically unmapped via device_release() when the last ref on the SPI controller is dropped. The additional iounmap() in the ->probe() error path is thus unnecessary. Signed-off-by: Lukas Wunner --- drivers/spi/spi-amd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index c7cfc3dc20b1..65b53eee5be9 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -285,14 +285,12 @@ static int amd_spi_probe(struct platform_device *pdev) err = spi_register_master(master); if (err) { dev_err(dev, "error %d registering SPI controller\n", err); - goto err_iounmap; + goto err_free_master; } platform_set_drvdata(pdev, amd_spi); return 0; -err_iounmap: - iounmap(amd_spi->io_remap_addr); err_free_master: spi_master_put(master); From patchwork Mon May 4 11:12:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 214699 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1B68C3A5A9 for ; Mon, 4 May 2020 11:24:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C85E320721 for ; Mon, 4 May 2020 11:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728344AbgEDLYO (ORCPT ); Mon, 4 May 2020 07:24:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726445AbgEDLYO (ORCPT ); Mon, 4 May 2020 07:24:14 -0400 Received: from mailout3.hostsharing.net (mailout3.hostsharing.net [IPv6:2a01:4f8:150:2161:1:b009:f236:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28EC7C061A0E for ; Mon, 4 May 2020 04:24:14 -0700 (PDT) Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout3.hostsharing.net (Postfix) with ESMTPS id 4E7A6101E69A5; Mon, 4 May 2020 13:15:57 +0200 (CEST) Received: from localhost (unknown [87.130.102.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id CA9D560F2900; Mon, 4 May 2020 13:15:56 +0200 (CEST) X-Mailbox-Line: From 689f29a359718dab4f5de9ee66c02ea97b3bd9e8 Mon Sep 17 00:00:00 2001 Message-Id: <689f29a359718dab4f5de9ee66c02ea97b3bd9e8.1588590210.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Mon, 4 May 2020 13:12:02 +0200 Subject: [PATCH 2/5] spi: amd: Pass probe errors back to driver core To: Mark Brown , "Sanjay R Mehta" Cc: linux-spi@vger.kernel.org Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org If probing fails, the AMD SPI driver pretends success to the driver core by returning 0. Return the errno instead. Signed-off-by: Lukas Wunner --- drivers/spi/spi-amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index 65b53eee5be9..a4248b97b67e 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -294,7 +294,7 @@ static int amd_spi_probe(struct platform_device *pdev) err_free_master: spi_master_put(master); - return 0; + return err; } static int amd_spi_remove(struct platform_device *pdev) From patchwork Mon May 4 11:12:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 214701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C713C3A5A9 for ; Mon, 4 May 2020 11:18:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E786E20721 for ; Mon, 4 May 2020 11:17:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbgEDLR7 (ORCPT ); Mon, 4 May 2020 07:17:59 -0400 Received: from mailout1.hostsharing.net ([83.223.95.204]:45283 "EHLO mailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726445AbgEDLR7 (ORCPT ); Mon, 4 May 2020 07:17:59 -0400 X-Greylist: delayed 343 seconds by postgrey-1.27 at vger.kernel.org; Mon, 04 May 2020 07:17:58 EDT Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout1.hostsharing.net (Postfix) with ESMTPS id B181810044AA5; Mon, 4 May 2020 13:17:57 +0200 (CEST) Received: from localhost (unknown [87.130.102.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 7FDA060F2900; Mon, 4 May 2020 13:17:57 +0200 (CEST) X-Mailbox-Line: From 5e53ccdf1eecd4e015dba99d0d77389107f8a2e3 Mon Sep 17 00:00:00 2001 Message-Id: <5e53ccdf1eecd4e015dba99d0d77389107f8a2e3.1588590210.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Mon, 4 May 2020 13:12:04 +0200 Subject: [PATCH 4/5] spi: amd: Fix refcount underflow on remove To: Mark Brown , "Sanjay R Mehta" Cc: linux-spi@vger.kernel.org Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The AMD SPI driver calls spi_master_put() in its ->remove() hook even though the preceding call to spi_unregister_master() already drops a ref, thus leading to a refcount underflow. Drop the superfluous call to spi_master_put(). This only leaves the call to spi_unregister_master() in the ->remove() hook, so it's safe to change the ->probe() hook to use the devm version of spi_register_master() and drop the ->remove() hook altogether. Signed-off-by: Lukas Wunner --- drivers/spi/spi-amd.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index d3e3516ef957..00f2f3405e08 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -282,7 +282,7 @@ static int amd_spi_probe(struct platform_device *pdev) master->transfer_one_message = amd_spi_master_transfer; /* Register the controller with SPI framework */ - err = spi_register_master(master); + err = devm_spi_register_master(dev, master); if (err) { dev_err(dev, "error %d registering SPI controller\n", err); goto err_free_master; @@ -296,16 +296,6 @@ static int amd_spi_probe(struct platform_device *pdev) return err; } -static int amd_spi_remove(struct platform_device *pdev) -{ - struct amd_spi *amd_spi = platform_get_drvdata(pdev); - - spi_unregister_master(amd_spi->master); - spi_master_put(amd_spi->master); - - return 0; -} - static const struct acpi_device_id spi_acpi_match[] = { { "AMDI0061", 0 }, {}, @@ -318,7 +308,6 @@ static struct platform_driver amd_spi_driver = { .acpi_match_table = ACPI_PTR(spi_acpi_match), }, .probe = amd_spi_probe, - .remove = amd_spi_remove, }; module_platform_driver(amd_spi_driver);