From patchwork Fri Apr 11 01:08:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 14047455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3082C3601E for ; Fri, 11 Apr 2025 01:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hnlplJMrlaC0dMDphlz7L6UrksHDLVz2lzXrxKirevo=; b=bjgnLH6jWkbHMYc2q5dKnbdEsX ibb7NIdDmaj+E3IVUxCOeFGXIhXM5TeTyWR8mqzyk3GNJqI4ZAl3YKz231LodGP/UVkDprOLCh9Ni Au9Ah0wvs6p7mURS4WP24hJCwe29AcR8foiWnT/nMA/ajMs+51db/ESfHuj5Sg5ct8fM3leBmGrFg 0M46iTVaOKPNWSop4yOYwmRZPhUCw0UPwm7o+3N4gN6AvWObh86hsE6LJpKBIUrpG/HEcN+JZ4A2a 1v3Bf9VaDOMbhvdHjqh1tQBqJFsNom7y6S5jPBYbkOmJfhS+gIXQy4Wic1bd5aF1CbMeYwsabfw9J OOCg/04w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u332Q-0000000CE2G-21ds; Fri, 11 Apr 2025 01:18:34 +0000 Received: from pi.codeconstruct.com.au ([203.29.241.158] helo=codeconstruct.com.au) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u32tR-0000000CCQz-02jE for linux-arm-kernel@lists.infradead.org; Fri, 11 Apr 2025 01:09:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1744333748; bh=hnlplJMrlaC0dMDphlz7L6UrksHDLVz2lzXrxKirevo=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=BLcxJ+QLELrze4REYr90Q/cG0vzVyXSOZ3z4M8SFXbh9M+CsbEEgDjcznKmzeWLAS 1EBqwvzDyEehnzXHXtNScVMwfoYTrofIivVW/11368Do8nQo1qW72byMhpb24LIbYb EF1RcSl22u/vuelr9vkXViZv7Ir8QcnvhnP5a03oxtLj8yppk22MJqyeYNehkStU/c FDNWfxoEzJvCqe8SuLjuwkZZJmcosjxH1dH+sBWY0M1h+wsUMb4QPijgoUEpaUlFej /1FAEx5XuTRS/g8RBQ4GbzLbov9LbwWo9kIzM6ONztVJCDN5y/kbFn3jxHWMwCJf92 /UyqdHzefeObw== Received: from [127.0.1.1] (unknown [180.150.112.225]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id B97DA7D70E; Fri, 11 Apr 2025 09:09:07 +0800 (AWST) From: Andrew Jeffery Date: Fri, 11 Apr 2025 10:38:31 +0930 Subject: [PATCH 1/7] soc: aspeed: lpc-snoop: Cleanup resources in stack-order MIME-Version: 1.0 Message-Id: <20250411-aspeed-lpc-snoop-fixes-v1-1-64f522e3ad6f@codeconstruct.com.au> References: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> In-Reply-To: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> To: linux-aspeed@lists.ozlabs.org Cc: Joel Stanley , Henry Martin , Jean Delvare , Patrick Rudolph , Andrew Geissler , Ninad Palsule , Patrick Venture , Robert Lippert , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Jeffery , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250410_180917_285857_B3D05C75 X-CRM114-Status: UNSURE ( 9.00 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Free the kfifo after unregistering the miscdev in aspeed_lpc_disable_snoop() as the kfifo is initialised before the miscdev in aspeed_lpc_enable_snoop(). Fixes: 3772e5da4454 ("drivers/misc: Aspeed LPC snoop output using misc chardev") Cc: stable@vger.kernel.org Cc: Jean Delvare Signed-off-by: Andrew Jeffery --- drivers/soc/aspeed/aspeed-lpc-snoop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c index 3e3f178b122615b33e10ff25a0b0fe7b40a0b667..bfa770ec51a889260d11c26e675f3320bf710a54 100644 --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c @@ -263,8 +263,8 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, return; } - kfifo_free(&lpc_snoop->chan[channel].fifo); misc_deregister(&lpc_snoop->chan[channel].miscdev); + kfifo_free(&lpc_snoop->chan[channel].fifo); } static int aspeed_lpc_snoop_probe(struct platform_device *pdev) From patchwork Fri Apr 11 01:08:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 14047450 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41EA0C3601E for ; Fri, 11 Apr 2025 01:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BdcEfSnP4+tv/vsPgvq3tc45liclW2ZxqOGrHE4nuw8=; b=kP59GXCOsHTc9zOBgatz40qSsk r88Zb6T+82rKjw5hlXS2RkHq59SwrBb+Sm/d8OFUgZ5Ou9+qEMgh+m5dHpLR2vvEfGHGxF949XdxM QOCbaxnoXx/bfBNjP3tijWPCGqm/4NJSG3hXECOhkUEx6oPQe+HTuR9DmT0fIjqJzwdw3snNwV+r8 oxBj9SXwYLsQIbMoPs2snVU8RZG2gtoaEsLxrDyjxkO2DDpkSSotfaATEqc/xdcDYbMaliaQU24s3 TzGKEKfIdMzfwRQcGBTJ7QLhrK4PuYekG+t+EJN0/1sTT9EuZQ74nD7aRXq0o3hhk+CTZLuMNCIT3 re5Qk87g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u32x4-0000000CDJS-0jHa; Fri, 11 Apr 2025 01:13:02 +0000 Received: from pi.codeconstruct.com.au ([203.29.241.158] helo=codeconstruct.com.au) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u32tQ-0000000CCQx-4BOv for linux-arm-kernel@lists.infradead.org; Fri, 11 Apr 2025 01:09:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1744333749; bh=BdcEfSnP4+tv/vsPgvq3tc45liclW2ZxqOGrHE4nuw8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=keDpANHK5Ihkfq6mIdraefIFVCXBZmQaUdK5Fm8TUYv9xq9zgg3c81wcxXx4LOEIU 2OHOgEqsATY6Jve865aE91SfJAU2hNcGkXLPFyRh9+nsaUJ3IWdJlyXzfiC5efcIRJ beJRP6TqpVl3Jnx4Kja1zIVh4+D7t5Kbz20yWFhpPfPdaTI7MOtLu2ypM5EHh0HdPj lgUHUuKOhmHsvJ0lox9ylWR14nK7Ss8nWuFmEG1Xy0NywJcCfmrHdRlTW6Ku4TQdUb 0j8P521B/ZwEcX88/axCjxsw49SgFChKEVLLAI09l/M7JM789vmSZ6I/PuS0ftp6ov 4wIS31AIIXigQ== Received: from [127.0.1.1] (unknown [180.150.112.225]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id 77A017D710; Fri, 11 Apr 2025 09:09:08 +0800 (AWST) From: Andrew Jeffery Date: Fri, 11 Apr 2025 10:38:32 +0930 Subject: [PATCH 2/7] soc: aspeed: lpc-snoop: Don't disable channels that aren't enabled MIME-Version: 1.0 Message-Id: <20250411-aspeed-lpc-snoop-fixes-v1-2-64f522e3ad6f@codeconstruct.com.au> References: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> In-Reply-To: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> To: linux-aspeed@lists.ozlabs.org Cc: Joel Stanley , Henry Martin , Jean Delvare , Patrick Rudolph , Andrew Geissler , Ninad Palsule , Patrick Venture , Robert Lippert , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Jeffery , stable@vger.kernel.org X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250410_180917_274359_B3F1C2EA X-CRM114-Status: GOOD ( 10.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Mitigate e.g. the following: # echo 1e789080.lpc-snoop > /sys/bus/platform/drivers/aspeed-lpc-snoop/unbind ... [ 120.363594] Unable to handle kernel NULL pointer dereference at virtual address 00000004 when write [ 120.373866] [00000004] *pgd=00000000 [ 120.377910] Internal error: Oops: 805 [#1] SMP ARM [ 120.383306] CPU: 1 UID: 0 PID: 315 Comm: sh Not tainted 6.15.0-rc1-00009-g926217bc7d7d-dirty #20 NONE ... [ 120.679543] Call trace: [ 120.679559] misc_deregister from aspeed_lpc_snoop_remove+0x84/0xac [ 120.692462] aspeed_lpc_snoop_remove from platform_remove+0x28/0x38 [ 120.700996] platform_remove from device_release_driver_internal+0x188/0x200 ... Fixes: 9f4f9ae81d0a ("drivers/misc: add Aspeed LPC snoop driver") Cc: stable@vger.kernel.org Cc: Jean Delvare Signed-off-by: Andrew Jeffery --- drivers/soc/aspeed/aspeed-lpc-snoop.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c index bfa770ec51a889260d11c26e675f3320bf710a54..e9d9a8e60a6f062c0b53c9c02e5d73768453998d 100644 --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c @@ -58,6 +58,7 @@ struct aspeed_lpc_snoop_model_data { }; struct aspeed_lpc_snoop_channel { + bool enabled; struct kfifo fifo; wait_queue_head_t wq; struct miscdevice miscdev; @@ -190,6 +191,9 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, const struct aspeed_lpc_snoop_model_data *model_data = of_device_get_match_data(dev); + if (lpc_snoop->chan[channel].enabled) + return -EBUSY; + init_waitqueue_head(&lpc_snoop->chan[channel].wq); /* Create FIFO datastructure */ rc = kfifo_alloc(&lpc_snoop->chan[channel].fifo, @@ -236,6 +240,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, regmap_update_bits(lpc_snoop->regmap, HICRB, hicrb_en, hicrb_en); + lpc_snoop->chan[channel].enabled = true; + return 0; err_misc_deregister: @@ -248,6 +254,9 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, int channel) { + if (!lpc_snoop->chan[channel].enabled) + return; + switch (channel) { case 0: regmap_update_bits(lpc_snoop->regmap, HICR5, @@ -263,6 +272,8 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, return; } + lpc_snoop->chan[channel].enabled = false; + /* Consider improving safety wrt concurrent reader(s) */ misc_deregister(&lpc_snoop->chan[channel].miscdev); kfifo_free(&lpc_snoop->chan[channel].fifo); } From patchwork Fri Apr 11 01:08:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 14047449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C48E7C3601E for ; Fri, 11 Apr 2025 01:11:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Kl9cNe70ebuqUBsGg3wclmdapJ/BbYZ4gItW6jHIc7A=; b=epSxuUOExVUH6y0igNQs5fl6tV URbVYvFOmmFOWpSy/zCK9JUnTmrdbQkIP3fFXStuMDSxzkOj0WYxTTqC+LY56tS+r7huaNvED+Fxg Yi8LyLN4/VpVPwPq0Vy22Xqtgb4ZyDxq6Ezj7+LCtPfnZSk2gCQVp3F+6AwvuOG6tre9ndO9UHz8h AxqSdHyb+l/zhr9MzeyeA/A51PcQgMyAPRzJ192bISBBsbz31aJ+0RgSOH7rXXKj1LyHm46PuUo58 OtnJr+R/P7+eIGSKKnEd6JTwl7wsmpoWtoOtS0WigqC5bVQEOAM5dZ9x6UNg67C2VIxDlydPIToNu FoEhGJFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u32vH-0000000CCyW-25Ag; Fri, 11 Apr 2025 01:11:11 +0000 Received: from pi.codeconstruct.com.au ([203.29.241.158] helo=codeconstruct.com.au) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u32tR-0000000CCR0-00oA for linux-arm-kernel@lists.infradead.org; Fri, 11 Apr 2025 01:09:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1744333749; bh=Kl9cNe70ebuqUBsGg3wclmdapJ/BbYZ4gItW6jHIc7A=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=KXybtiEpVaRs6sAGdOtnmP9rQxsNzrAWJmdNkLK8ew7d8QxZs4QbeawJkPJVvlGYE kqYN+QPIEr2LOIxkxWgr2NjAowCKjUwCHvNbLmMSyLR7qUkPolYIgpnpWyUpupKQsJ wxAzji6m4w24QEKZHRAbdORveQcLoi+OWJVPb4BDSrxBYVfHp2JrTWXny7XinCq+Tu Vcz/WVUl33+nQkgXC1Ji/Zpx2O+G9Fw1dMcujg6GCyxCOXGLc+cChI2/R6Zi+0025x 9OnfmrhQZ2TQTXGqaW6izUHRwuev4+qYKqQQe8ekXqSEjAY3YwmSfMBrtXgZwPtOjP wq48PWVT/MeMw== Received: from [127.0.1.1] (unknown [180.150.112.225]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id 4EECF7D712; Fri, 11 Apr 2025 09:09:09 +0800 (AWST) From: Andrew Jeffery Date: Fri, 11 Apr 2025 10:38:33 +0930 Subject: [PATCH 3/7] soc: aspeed: lpc-snoop: Ensure model_data is valid MIME-Version: 1.0 Message-Id: <20250411-aspeed-lpc-snoop-fixes-v1-3-64f522e3ad6f@codeconstruct.com.au> References: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> In-Reply-To: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> To: linux-aspeed@lists.ozlabs.org Cc: Joel Stanley , Henry Martin , Jean Delvare , Patrick Rudolph , Andrew Geissler , Ninad Palsule , Patrick Venture , Robert Lippert , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Jeffery X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250410_180917_255464_4FB79AF0 X-CRM114-Status: GOOD ( 10.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org of_device_get_match_data() can return NULL, though shouldn't in current circumstances. Regardless, initialise model_data closer to use so it's clear we need to test for validity prior to dereferencing. Fixes: 2dee584bc9e3 ("drivers/misc: (aspeed-lpc-snoop): Add ast2400 to compat") Signed-off-by: Andrew Jeffery --- drivers/soc/aspeed/aspeed-lpc-snoop.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c index e9d9a8e60a6f062c0b53c9c02e5d73768453998d..28f034b8a3b7226efe20cbe30a7da0c2b49fbd96 100644 --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c @@ -186,10 +186,10 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, struct device *dev, int channel, u16 lpc_port) { - int rc = 0; + const struct aspeed_lpc_snoop_model_data *model_data; u32 hicr5_en, snpwadr_mask, snpwadr_shift, hicrb_en; - const struct aspeed_lpc_snoop_model_data *model_data = - of_device_get_match_data(dev); + int rc = 0; + if (lpc_snoop->chan[channel].enabled) return -EBUSY; @@ -236,9 +236,10 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, regmap_update_bits(lpc_snoop->regmap, HICR5, hicr5_en, hicr5_en); regmap_update_bits(lpc_snoop->regmap, SNPWADR, snpwadr_mask, lpc_port << snpwadr_shift); - if (model_data->has_hicrb_ensnp) - regmap_update_bits(lpc_snoop->regmap, HICRB, - hicrb_en, hicrb_en); + + model_data = of_device_get_match_data(dev); + if (model_data && model_data->has_hicrb_ensnp) + regmap_update_bits(lpc_snoop->regmap, HICRB, hicrb_en, hicrb_en); lpc_snoop->chan[channel].enabled = true; From patchwork Fri Apr 11 01:08:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 14047454 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2CA06C3601E for ; Fri, 11 Apr 2025 01:16:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ABw4ARhNQAkd4rlXFYixFM0InLDEdXfdXSG/4HG1QLQ=; b=XA0rvA2lB4ASohP+IgS565N6rl FEf+1u2obt48YjUHO8Jtz5prQ2HEKFMYdr71C7DS7PAbJ14kDw+147Q5tOcXJmdw7zv2k+Hp7yA4e S2wRoXTm1y1GAH0My1VPEKk2Zuxu/XhaYmDBY6/9jmEjgUXwJ6QQIuqL/wlFEFOke7UuvuAPmS7A8 qZnpQ2MiN8A+OAy8q8EUHq1VUBkutgEVwrfjyl0c6I+5F/AFozP90JDLbXRZe+RABHNSUF3V7kQG1 DU2cGisYWbysRIUZjhXDnYt9sww5i1i+06nuTise3u9rn90850q9Un788i/NXO4w0WM1cqPCygiGk eenbgVNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u330e-0000000CDt7-2fLO; Fri, 11 Apr 2025 01:16:44 +0000 Received: from pi.codeconstruct.com.au ([203.29.241.158] helo=codeconstruct.com.au) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u32tQ-0000000CCR4-4BBY for linux-arm-kernel@lists.infradead.org; Fri, 11 Apr 2025 01:09:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1744333750; bh=ABw4ARhNQAkd4rlXFYixFM0InLDEdXfdXSG/4HG1QLQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=So5fjgqt9a9pj2mC+YdxESJ/ZFNZh4U8IMB+HEFP0wC04D7yukXU067Ok9Fudgw5m I/eFeoUIFghXlhYObM+Q0OFIVkjRMLYNiu2/zlSSBu0rnT5+AkmvrCztE7AF2i7Zw5 do7euB8rxbndWNAiuvpLeL807qtoFuGMPdPKWfjbpQQIiH4VUR44T2fyDXmZ3g7Rdp pzlUl7giYfvNYNWQ9kxC1H7WVwzwln1zHX87DRf4BbF5qbLa4qEzyyvMxHJN06w9Lg YHZO5UtF2UHjq5jitMgrBk8vBnDhj+T9jKTp1rCFPr8YvrhJUP3ufKJtUftKgK3aep a9802cCCXkNWg== Received: from [127.0.1.1] (unknown [180.150.112.225]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id 01ECA7D714; Fri, 11 Apr 2025 09:09:09 +0800 (AWST) From: Andrew Jeffery Date: Fri, 11 Apr 2025 10:38:34 +0930 Subject: [PATCH 4/7] soc: aspeed: lpc-snoop: Constrain parameters in channel paths MIME-Version: 1.0 Message-Id: <20250411-aspeed-lpc-snoop-fixes-v1-4-64f522e3ad6f@codeconstruct.com.au> References: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> In-Reply-To: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> To: linux-aspeed@lists.ozlabs.org Cc: Joel Stanley , Henry Martin , Jean Delvare , Patrick Rudolph , Andrew Geissler , Ninad Palsule , Patrick Venture , Robert Lippert , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Jeffery X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250410_180917_281294_937B4041 X-CRM114-Status: UNSURE ( 8.07 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Ensure pointers and the channel index are valid before use. Fixes: 9f4f9ae81d0a ("drivers/misc: add Aspeed LPC snoop driver") Signed-off-by: Andrew Jeffery --- drivers/soc/aspeed/aspeed-lpc-snoop.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c index 28f034b8a3b7226efe20cbe30a7da0c2b49fbd96..6ab362aeb180c8ad356422d8257717f41a232b3c 100644 --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c @@ -182,6 +182,7 @@ static int aspeed_lpc_snoop_config_irq(struct aspeed_lpc_snoop *lpc_snoop, return 0; } +__attribute__((nonnull)) static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, struct device *dev, int channel, u16 lpc_port) @@ -190,6 +191,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, u32 hicr5_en, snpwadr_mask, snpwadr_shift, hicrb_en; int rc = 0; + if (channel < 0 || channel >= ARRAY_SIZE(lpc_snoop->chan)) + return -EINVAL; if (lpc_snoop->chan[channel].enabled) return -EBUSY; @@ -252,9 +255,13 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, return rc; } +__attribute__((nonnull)) static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, int channel) { + if (channel < 0 || channel >= ARRAY_SIZE(lpc_snoop->chan)) + return; + if (!lpc_snoop->chan[channel].enabled) return; From patchwork Fri Apr 11 01:08:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 14047456 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62318C3601E for ; Fri, 11 Apr 2025 01:20:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5d2qecfXxLFsaK8953Ze2wHaQJoHjLdmHiRZ/zMT2W4=; b=n6oiDH2m2PFdXGzy1OerUPON7+ x3yIjKtibbu6ba6J+OXdH4MS/6XcBrqCTz1gpsHheGs9npvib8ezJyZFX2/TJn4pxMQwr5nNGQtBL OORlAR4HUIzwZ4dZg1gfrWMdyx99KXNVgysB8m+2/CLoLvwmRE3YLpdsNVK3MvK2QBi882e2C1Q6x tkJUJm3xC+J2KbGohmAcV2yF0dbXRLP/M6FL9ONV9iBjKB/khNpaH6g5TOZwrOlpm3bCOOQ89t5FF 1ljfWaTuksI6Mf0MswzGokSg7zv6PqWi9+Ic+5A5UAT7k7MjyrbYxV2QsX5so3R40zFotTUxgbDaI cyvc7fAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u334E-0000000CEEi-0a9H; Fri, 11 Apr 2025 01:20:26 +0000 Received: from pi.codeconstruct.com.au ([203.29.241.158] helo=codeconstruct.com.au) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u32tU-0000000CCTw-0LX3 for linux-arm-kernel@lists.infradead.org; Fri, 11 Apr 2025 01:09:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1744333751; bh=5d2qecfXxLFsaK8953Ze2wHaQJoHjLdmHiRZ/zMT2W4=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=RxRK3urbtqHCux2yvKr3Gday1m7MxlHZfjP51M0pU7PtXXAT6nSXsvkkTYg3uMMzL /gkibMwHZ0RtmYUM63NDsXRhzokmXqknjY4/NNbs/0/6cA6SNZ+9icNt9jF1oNGGcj 3fACPSlg+D8I4YoBhHbIoSs0d+4bEEoSEiUdQXcfdxBdLLJsLJToHz7kpZAaO5rmYF WGbYEV5lG01NjsKuKcrqj9K/RjQcBwDTllRIi65WReUgZleU2ZY9p55O2U+bffwH/o /SGlyOXaBms/TwX/EibCD6hT3lMLAhPl0C4p2fU6Z5zZzaR+T3sWPtIxbiK5XEdI4g 0CvxqQkgLB8Rg== Received: from [127.0.1.1] (unknown [180.150.112.225]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id A59267D715; Fri, 11 Apr 2025 09:09:10 +0800 (AWST) From: Andrew Jeffery Date: Fri, 11 Apr 2025 10:38:35 +0930 Subject: [PATCH 5/7] soc: aspeed: lpc-snoop: Rename 'channel' to 'index' in channel paths MIME-Version: 1.0 Message-Id: <20250411-aspeed-lpc-snoop-fixes-v1-5-64f522e3ad6f@codeconstruct.com.au> References: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> In-Reply-To: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> To: linux-aspeed@lists.ozlabs.org Cc: Joel Stanley , Henry Martin , Jean Delvare , Patrick Rudolph , Andrew Geissler , Ninad Palsule , Patrick Venture , Robert Lippert , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Jeffery X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250410_180920_344193_6256E0EF X-CRM114-Status: GOOD ( 12.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We'll introduce another 'channel' variable shortly Signed-off-by: Andrew Jeffery --- drivers/soc/aspeed/aspeed-lpc-snoop.c | 47 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c index 6ab362aeb180c8ad356422d8257717f41a232b3c..f6952f71eda52c95aea5ad1084edd218b88f1234 100644 --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c @@ -185,40 +185,40 @@ static int aspeed_lpc_snoop_config_irq(struct aspeed_lpc_snoop *lpc_snoop, __attribute__((nonnull)) static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, struct device *dev, - int channel, u16 lpc_port) + int index, u16 lpc_port) { const struct aspeed_lpc_snoop_model_data *model_data; u32 hicr5_en, snpwadr_mask, snpwadr_shift, hicrb_en; int rc = 0; - if (channel < 0 || channel >= ARRAY_SIZE(lpc_snoop->chan)) + if (index < 0 || index >= ARRAY_SIZE(lpc_snoop->chan)) return -EINVAL; - if (lpc_snoop->chan[channel].enabled) + if (lpc_snoop->chan[index].enabled) return -EBUSY; - init_waitqueue_head(&lpc_snoop->chan[channel].wq); + init_waitqueue_head(&lpc_snoop->chan[index].wq); /* Create FIFO datastructure */ - rc = kfifo_alloc(&lpc_snoop->chan[channel].fifo, + rc = kfifo_alloc(&lpc_snoop->chan[index].fifo, SNOOP_FIFO_SIZE, GFP_KERNEL); if (rc) return rc; - lpc_snoop->chan[channel].miscdev.minor = MISC_DYNAMIC_MINOR; - lpc_snoop->chan[channel].miscdev.name = - devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, channel); - if (!lpc_snoop->chan[channel].miscdev.name) { + lpc_snoop->chan[index].miscdev.minor = MISC_DYNAMIC_MINOR; + lpc_snoop->chan[index].miscdev.name = + devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, index); + if (!lpc_snoop->chan[index].miscdev.name) { rc = -ENOMEM; goto err_free_fifo; } - lpc_snoop->chan[channel].miscdev.fops = &snoop_fops; - lpc_snoop->chan[channel].miscdev.parent = dev; - rc = misc_register(&lpc_snoop->chan[channel].miscdev); + lpc_snoop->chan[index].miscdev.fops = &snoop_fops; + lpc_snoop->chan[index].miscdev.parent = dev; + rc = misc_register(&lpc_snoop->chan[index].miscdev); if (rc) goto err_free_fifo; /* Enable LPC snoop channel at requested port */ - switch (channel) { + switch (index) { case 0: hicr5_en = HICR5_EN_SNP0W | HICR5_ENINT_SNP0W; snpwadr_mask = SNPWADR_CH0_MASK; @@ -244,28 +244,29 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, if (model_data && model_data->has_hicrb_ensnp) regmap_update_bits(lpc_snoop->regmap, HICRB, hicrb_en, hicrb_en); - lpc_snoop->chan[channel].enabled = true; + lpc_snoop->chan[index].enabled = true; return 0; err_misc_deregister: - misc_deregister(&lpc_snoop->chan[channel].miscdev); + misc_deregister(&lpc_snoop->chan[index].miscdev); err_free_fifo: - kfifo_free(&lpc_snoop->chan[channel].fifo); + kfifo_free(&lpc_snoop->chan[index].fifo); return rc; } __attribute__((nonnull)) static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, - int channel) + int index) { - if (channel < 0 || channel >= ARRAY_SIZE(lpc_snoop->chan)) + if (index < 0 || index >= ARRAY_SIZE(lpc_snoop->chan)) return; - if (!lpc_snoop->chan[channel].enabled) + if (!lpc_snoop->chan[index].enabled) return; - switch (channel) { + /* Disable interrupts along with the device */ + switch (index) { case 0: regmap_update_bits(lpc_snoop->regmap, HICR5, HICR5_EN_SNP0W | HICR5_ENINT_SNP0W, @@ -280,10 +281,10 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, return; } - lpc_snoop->chan[channel].enabled = false; + lpc_snoop->chan[index].enabled = false; /* Consider improving safety wrt concurrent reader(s) */ - misc_deregister(&lpc_snoop->chan[channel].miscdev); - kfifo_free(&lpc_snoop->chan[channel].fifo); + misc_deregister(&lpc_snoop->chan[index].miscdev); + kfifo_free(&lpc_snoop->chan[index].fifo); } static int aspeed_lpc_snoop_probe(struct platform_device *pdev) From patchwork Fri Apr 11 01:08:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 14047460 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14ACCC3601E for ; Fri, 11 Apr 2025 01:24:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KFtQnngCykasdCrNVPG+SOfUzKEa2z4spwHYuIB44t0=; b=N83S2AtfDx+Lt10FP+bkm2fs4P V+c4ALLC/6td6O0JzEfBEiXpCaYHUQJFpXD+peuzNvN4qKY4EZxHeAk8IbD1eokCDJN1nvKO+YExF opKp9fM+SSfbYkbVbF0ePayZg6EJNZ0cVJS/jDUELTnV8Oh41gaXl41Z4B5/DV1mt2w6NOyIK5LnM cigeXBRyMJzM18CEqZVcLLwcFSnA/KvdZKNN3WzDx3Ow0Mq6bH1eWdWhIO8FR/IAvEb6ylhI+/FNx K1N7201k7ywED0FJTNiCRH6KJ5RUIU5yYw8s4K5jQ8XsQYpBPi2lRR5gJcNON09Q3NS+peo40ZZik 81ji47Ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u337l-0000000CEgD-2blV; Fri, 11 Apr 2025 01:24:05 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u32tv-0000000CCbT-09fM for linux-arm-kernel@bombadil.infradead.org; Fri, 11 Apr 2025 01:09:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=KFtQnngCykasdCrNVPG+SOfUzKEa2z4spwHYuIB44t0=; b=SVOrHkhzaX1DKjk+cIvOuY65yb YNuoTr+JEuOAZ0eAOGGkxmtnXqXwh9pDkKM3+JaJIhNNc3IQWuVvQOtUvcXJbklUcJs9gtCLZozO+ KgjZsB1mjJZT1Rf4+b2e5kKM6pgEM0OXRzTrdcejkhNvdyZ/GcborTh7QXSb6Yr8zQSf2HmD1aGw0 pESpnF7WTROfkPSrz2zki9ppgXjRYl2+SV3otiO3L9qot2mA3A2yEuCTz53o8VxQyyBkD7fkG/CW2 O71Y1msZQOPqRGijqPkWo5fXFcsaT5FZdiVF/UNZlTJQST5RtO8FbCaN+0RSBA8EBja6J4NmCLjyN nYaWbNMA==; Received: from pi.codeconstruct.com.au ([203.29.241.158] helo=codeconstruct.com.au) by desiato.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u32tg-00000008tnA-3xSF for linux-arm-kernel@lists.infradead.org; Fri, 11 Apr 2025 01:09:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1744333751; bh=KFtQnngCykasdCrNVPG+SOfUzKEa2z4spwHYuIB44t0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=dKMosy8m20GXWuALQvsB5mTGk5kl0tE3piF8e7cwOm5XQ8KseCkLjXYYUmwKiqbE6 1qa17aCynswRn9iV8qacBrl5Z5l88Qxjep/zHkFS1TojBwrEMC+DAD6v8sd1fOdXSQ RxGlKd0VIrrxUWtHhGHAFe22mlF5sFG+d93/t1+pF6b9/yTNL5KMHQd8ArbbaL4NO6 fp9T9z6tePrn5RSDye+wU44jh9HhwnevrBBUl7mM5HM90/0uuMpqyFNlk2j+7ZqHDc fgj2HJSo7KuuhoP+y7vD6zpzP62u116jrACB1q6D29o2robOLCK1ZLsquhetr4gC8h nwyISRwGGEOhQ== Received: from [127.0.1.1] (unknown [180.150.112.225]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id 562D97D716; Fri, 11 Apr 2025 09:09:11 +0800 (AWST) From: Andrew Jeffery Date: Fri, 11 Apr 2025 10:38:36 +0930 Subject: [PATCH 6/7] soc: aspeed: lpc-snoop: Rearrange channel paths MIME-Version: 1.0 Message-Id: <20250411-aspeed-lpc-snoop-fixes-v1-6-64f522e3ad6f@codeconstruct.com.au> References: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> In-Reply-To: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> To: linux-aspeed@lists.ozlabs.org Cc: Joel Stanley , Henry Martin , Jean Delvare , Patrick Rudolph , Andrew Geissler , Ninad Palsule , Patrick Venture , Robert Lippert , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Jeffery X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250411_020939_535778_8DCFAB31 X-CRM114-Status: GOOD ( 12.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Order assignments such that tests for conditions not involving resource acquisition are ordered before those testing acquired resources, and order managed resource acquisition before unmanaged where possible. This way we minimise the amount of manual cleanup required. In the process, improve readability of the code by introducing a channel pointer that takes the place of the repeated object lookups. Signed-off-by: Andrew Jeffery --- drivers/soc/aspeed/aspeed-lpc-snoop.c | 47 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c index f6952f71eda52c95aea5ad1084edd218b88f1234..0b2044fd79b1be08dfa33bfcaf249b020c909bb9 100644 --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c @@ -189,31 +189,33 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, { const struct aspeed_lpc_snoop_model_data *model_data; u32 hicr5_en, snpwadr_mask, snpwadr_shift, hicrb_en; + struct aspeed_lpc_snoop_channel *channel; int rc = 0; if (index < 0 || index >= ARRAY_SIZE(lpc_snoop->chan)) return -EINVAL; - if (lpc_snoop->chan[index].enabled) + channel = &lpc_snoop->chan[index]; + + if (channel->enabled) return -EBUSY; - init_waitqueue_head(&lpc_snoop->chan[index].wq); - /* Create FIFO datastructure */ - rc = kfifo_alloc(&lpc_snoop->chan[index].fifo, - SNOOP_FIFO_SIZE, GFP_KERNEL); + init_waitqueue_head(&channel->wq); + + channel->miscdev.minor = MISC_DYNAMIC_MINOR; + channel->miscdev.fops = &snoop_fops; + channel->miscdev.parent = dev; + + channel->miscdev.name = + devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, index); + if (!channel->miscdev.name) + return -ENOMEM; + + rc = kfifo_alloc(&channel->fifo, SNOOP_FIFO_SIZE, GFP_KERNEL); if (rc) return rc; - lpc_snoop->chan[index].miscdev.minor = MISC_DYNAMIC_MINOR; - lpc_snoop->chan[index].miscdev.name = - devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, index); - if (!lpc_snoop->chan[index].miscdev.name) { - rc = -ENOMEM; - goto err_free_fifo; - } - lpc_snoop->chan[index].miscdev.fops = &snoop_fops; - lpc_snoop->chan[index].miscdev.parent = dev; - rc = misc_register(&lpc_snoop->chan[index].miscdev); + rc = misc_register(&channel->miscdev); if (rc) goto err_free_fifo; @@ -236,6 +238,7 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, goto err_misc_deregister; } + /* Enable LPC snoop channel at requested port */ regmap_update_bits(lpc_snoop->regmap, HICR5, hicr5_en, hicr5_en); regmap_update_bits(lpc_snoop->regmap, SNPWADR, snpwadr_mask, lpc_port << snpwadr_shift); @@ -244,7 +247,7 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, if (model_data && model_data->has_hicrb_ensnp) regmap_update_bits(lpc_snoop->regmap, HICRB, hicrb_en, hicrb_en); - lpc_snoop->chan[index].enabled = true; + channel->enabled = true; return 0; @@ -259,10 +262,14 @@ __attribute__((nonnull)) static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, int index) { + struct aspeed_lpc_snoop_channel *channel; + if (index < 0 || index >= ARRAY_SIZE(lpc_snoop->chan)) return; - if (!lpc_snoop->chan[index].enabled) + channel = &lpc_snoop->chan[index]; + + if (!channel->enabled) return; /* Disable interrupts along with the device */ @@ -281,10 +288,10 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, return; } - lpc_snoop->chan[index].enabled = false; + channel->enabled = false; /* Consider improving safety wrt concurrent reader(s) */ - misc_deregister(&lpc_snoop->chan[index].miscdev); - kfifo_free(&lpc_snoop->chan[index].fifo); + misc_deregister(&channel->miscdev); + kfifo_free(&channel->fifo); } static int aspeed_lpc_snoop_probe(struct platform_device *pdev) From patchwork Fri Apr 11 01:08:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 14047459 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6454AC3601E for ; Fri, 11 Apr 2025 01:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gIkAaCaSRxoDKHS10fE7AU9S0jyaF+J3B0+u4ydPtBo=; b=UdmAGlxwZNhVXfLr1pQMpUWiEo QFeLbIoH2YugDlCUIYpUwwb8PV8MqSBkSivPX4gIWXpdmYOQDsLNjKS7VQClBbUjbRXdhxxFMhBuz JTYdgIKOtE7zEuEAsvsFbn38gmT2GO2gXQuL0QkWm7ZIydqU+EbM3ASxfvh712ifj8puw2dVNrF4E YAnOrQQNcebmATk0ItDpTlhVh5EloTK8yvnv8Ks1f8FjZgfsssmyngZ4Dz5j73ZqcGokg6RjPaW3F BfxgVEeyLUFjdotA4nbQsehiF02/Aw64TEt4yc8D+wcF+rIhKBVnXDC5njCfFCgOlHeoB66uepyqQ il7afgRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u3360-0000000CERw-3xzp; Fri, 11 Apr 2025 01:22:16 +0000 Received: from pi.codeconstruct.com.au ([203.29.241.158] helo=codeconstruct.com.au) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u32tU-0000000CCU5-1QIQ for linux-arm-kernel@lists.infradead.org; Fri, 11 Apr 2025 01:09:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1744333752; bh=gIkAaCaSRxoDKHS10fE7AU9S0jyaF+J3B0+u4ydPtBo=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Q8c6qqoe+aZNDwwnV4L7OyUawRWb9tkB2mDBA6g0V4v6FjJVBOgcuXKiF4TcHubPT J+WwIuvytl9UydDMC7o2yZC6P7/4m0F1zzHaUlNygBrGOlVe+UPeaKMdKmwJRHIdx2 RiKE5z3xdHKX+QOcCfG7/ZDSRlZf4AwFu1L8t4rKRI6YLeRrUAhU66eAQCFTn/LCrK JKvQDNQPBBpgAfBggNqRMaqgsPruKNGtDWZXl0B1qYxcnkyq0G2+pLPLi+8SZCdWUL ltXjZ+6fo62eSYxrPS39qZPcB+LfR5sDyCiEqOLe7J00pbIgkUo/tKhS4LvEo/60Nt 2M2m3Zo1T3IwQ== Received: from [127.0.1.1] (unknown [180.150.112.225]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id 09C097D717; Fri, 11 Apr 2025 09:09:11 +0800 (AWST) From: Andrew Jeffery Date: Fri, 11 Apr 2025 10:38:37 +0930 Subject: [PATCH 7/7] soc: aspeed: lpc-snoop: Lift channel config to const structs MIME-Version: 1.0 Message-Id: <20250411-aspeed-lpc-snoop-fixes-v1-7-64f522e3ad6f@codeconstruct.com.au> References: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> In-Reply-To: <20250411-aspeed-lpc-snoop-fixes-v1-0-64f522e3ad6f@codeconstruct.com.au> To: linux-aspeed@lists.ozlabs.org Cc: Joel Stanley , Henry Martin , Jean Delvare , Patrick Rudolph , Andrew Geissler , Ninad Palsule , Patrick Venture , Robert Lippert , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Jeffery X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250410_180920_619175_94388212 X-CRM114-Status: GOOD ( 15.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The shifts and masks for each channel are defined by hardware and are not something that changes at runtime. Accordingly, describe the information in an array of const structs and associate elements with each channel instance, removing the need for the switch and handling of its default case. Signed-off-by: Andrew Jeffery --- drivers/soc/aspeed/aspeed-lpc-snoop.c | 82 +++++++++++++++++------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c index 0b2044fd79b1be08dfa33bfcaf249b020c909bb9..b54d8fbf7b83ebadd4fe1b16cbddf07a0bfac868 100644 --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c @@ -10,6 +10,7 @@ * 0x80 writes made by the BIOS during the boot process. */ +#include "linux/ratelimit.h" #include #include #include @@ -57,7 +58,15 @@ struct aspeed_lpc_snoop_model_data { unsigned int has_hicrb_ensnp; }; +struct aspeed_lpc_snoop_channel_cfg { + u32 hicr5_en; + u32 snpwadr_mask; + u32 snpwadr_shift; + u32 hicrb_en; +}; + struct aspeed_lpc_snoop_channel { + const struct aspeed_lpc_snoop_channel_cfg *cfg; bool enabled; struct kfifo fifo; wait_queue_head_t wq; @@ -188,7 +197,6 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, int index, u16 lpc_port) { const struct aspeed_lpc_snoop_model_data *model_data; - u32 hicr5_en, snpwadr_mask, snpwadr_shift, hicrb_en; struct aspeed_lpc_snoop_channel *channel; int rc = 0; @@ -200,6 +208,9 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, if (channel->enabled) return -EBUSY; + if (WARN_ONCE(!channel->cfg, "snoop channel %d lacks required config", index)) + return -EINVAL; + init_waitqueue_head(&channel->wq); channel->miscdev.minor = MISC_DYNAMIC_MINOR; @@ -220,39 +231,20 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, goto err_free_fifo; /* Enable LPC snoop channel at requested port */ - switch (index) { - case 0: - hicr5_en = HICR5_EN_SNP0W | HICR5_ENINT_SNP0W; - snpwadr_mask = SNPWADR_CH0_MASK; - snpwadr_shift = SNPWADR_CH0_SHIFT; - hicrb_en = HICRB_ENSNP0D; - break; - case 1: - hicr5_en = HICR5_EN_SNP1W | HICR5_ENINT_SNP1W; - snpwadr_mask = SNPWADR_CH1_MASK; - snpwadr_shift = SNPWADR_CH1_SHIFT; - hicrb_en = HICRB_ENSNP1D; - break; - default: - rc = -EINVAL; - goto err_misc_deregister; - } - - /* Enable LPC snoop channel at requested port */ - regmap_update_bits(lpc_snoop->regmap, HICR5, hicr5_en, hicr5_en); - regmap_update_bits(lpc_snoop->regmap, SNPWADR, snpwadr_mask, - lpc_port << snpwadr_shift); + regmap_update_bits(lpc_snoop->regmap, HICR5, channel->cfg->hicr5_en, + channel->cfg->hicr5_en); + regmap_update_bits(lpc_snoop->regmap, SNPWADR, channel->cfg->snpwadr_mask, + lpc_port << channel->cfg->snpwadr_shift); model_data = of_device_get_match_data(dev); if (model_data && model_data->has_hicrb_ensnp) - regmap_update_bits(lpc_snoop->regmap, HICRB, hicrb_en, hicrb_en); + regmap_update_bits(lpc_snoop->regmap, HICRB, channel->cfg->hicrb_en, + channel->cfg->hicrb_en); channel->enabled = true; return 0; -err_misc_deregister: - misc_deregister(&lpc_snoop->chan[index].miscdev); err_free_fifo: kfifo_free(&lpc_snoop->chan[index].fifo); return rc; @@ -272,21 +264,7 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, if (!channel->enabled) return; - /* Disable interrupts along with the device */ - switch (index) { - case 0: - regmap_update_bits(lpc_snoop->regmap, HICR5, - HICR5_EN_SNP0W | HICR5_ENINT_SNP0W, - 0); - break; - case 1: - regmap_update_bits(lpc_snoop->regmap, HICR5, - HICR5_EN_SNP1W | HICR5_ENINT_SNP1W, - 0); - break; - default: - return; - } + regmap_update_bits(lpc_snoop->regmap, HICR5, channel->cfg->hicr5_en, 0); channel->enabled = false; /* Consider improving safety wrt concurrent reader(s) */ @@ -294,6 +272,21 @@ static void aspeed_lpc_disable_snoop(struct aspeed_lpc_snoop *lpc_snoop, kfifo_free(&channel->fifo); } +static const struct aspeed_lpc_snoop_channel_cfg channel_cfgs[] = { + { + .hicr5_en = HICR5_EN_SNP0W | HICR5_ENINT_SNP0W, + .snpwadr_mask = SNPWADR_CH0_MASK, + .snpwadr_shift = SNPWADR_CH0_SHIFT, + .hicrb_en = HICRB_ENSNP0D, + }, + { + .hicr5_en = HICR5_EN_SNP1W | HICR5_ENINT_SNP1W, + .snpwadr_mask = SNPWADR_CH1_MASK, + .snpwadr_shift = SNPWADR_CH1_SHIFT, + .hicrb_en = HICRB_ENSNP1D, + }, +}; + static int aspeed_lpc_snoop_probe(struct platform_device *pdev) { struct aspeed_lpc_snoop *lpc_snoop; @@ -308,6 +301,13 @@ static int aspeed_lpc_snoop_probe(struct platform_device *pdev) if (!lpc_snoop) return -ENOMEM; + static_assert(ARRAY_SIZE(channel_cfgs) == ARRAY_SIZE(lpc_snoop->chan), + "Broken implementation assumption regarding cfg count"); + static_assert(ARRAY_SIZE(lpc_snoop->chan) == 2, + "Broken implementation assumption regarding channel count"); + lpc_snoop->chan[0].cfg = &channel_cfgs[0]; + lpc_snoop->chan[1].cfg = &channel_cfgs[1]; + np = pdev->dev.parent->of_node; if (!of_device_is_compatible(np, "aspeed,ast2400-lpc-v2") && !of_device_is_compatible(np, "aspeed,ast2500-lpc-v2") &&