From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56AD8EEB57E for ; Sat, 9 Sep 2023 00:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346077AbjIIAku (ORCPT ); Fri, 8 Sep 2023 20:40:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345872AbjIIAjm (ORCPT ); Fri, 8 Sep 2023 20:39:42 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9425326AC; Fri, 8 Sep 2023 17:39:05 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07A19C116AA; Sat, 9 Sep 2023 00:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694219932; bh=kHQ8Zxu29tMtvbD2hFU37TBol53NcdnB1rczZA0A1ck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TLFc0VKHlcNXKSr1O1y2PGypy34+jKva5+fjeOA6+RnCZQ5FGHlmGHYpqyn7Lk3Zp rUkiy0pKViFJ7m1AQ9AMhYp/3Ld1q9E7fOwD7gx7HLW4TN5UeFvYLk7v1TIDFazyoZ VhVzqdCT61QAMUd/hAw+Fy/7aEX5YjQLW1BdFh8c7q/yosbLa/3Emz77T2monfrHdc ZMxDH/02PJGT5SfkSgTRKmLyXl25PyzA6oV20f6b5J8M8Lar5+LW3KhwxOXcMUsB0m XtPdfVAj+2rUzemXAQoTnLvLn70XvvPsGqWnwgBBHLtguczrTNExKaOwvQW5b2NIIp AaMmf+UkByDeg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christophe Leroy , Greg Kroah-Hartman , Sasha Levin , jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, u.kleine-koenig@pengutronix.de, linux-serial@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 16/24] serial: cpm_uart: Avoid suspicious locking Date: Fri, 8 Sep 2023 20:38:08 -0400 Message-Id: <20230909003818.3580081-16-sashal@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230909003818.3580081-1-sashal@kernel.org> References: <20230909003818.3580081-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.52 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe Leroy [ Upstream commit 36ef11d311f405e55ad8e848c19b212ff71ef536 ] CHECK drivers/tty/serial/cpm_uart/cpm_uart_core.c drivers/tty/serial/cpm_uart/cpm_uart_core.c:1271:39: warning: context imbalance in 'cpm_uart_console_write' - unexpected unlock Allthough 'nolock' is not expected to change, sparse find the following form suspicious: if (unlikely(nolock)) { local_irq_save(flags); } else { spin_lock_irqsave(&pinfo->port.lock, flags); } cpm_uart_early_write(pinfo, s, count, true); if (unlikely(nolock)) { local_irq_restore(flags); } else { spin_unlock_irqrestore(&pinfo->port.lock, flags); } Rewrite it a more obvious form: if (unlikely(oops_in_progress)) { local_irq_save(flags); cpm_uart_early_write(pinfo, s, count, true); local_irq_restore(flags); } else { spin_lock_irqsave(&pinfo->port.lock, flags); cpm_uart_early_write(pinfo, s, count, true); spin_unlock_irqrestore(&pinfo->port.lock, flags); } Signed-off-by: Christophe Leroy Link: https://lore.kernel.org/r/f7da5cdc9287960185829cfef681a7d8614efa1f.1691068700.git.christophe.leroy@csgroup.eu Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/cpm_uart/cpm_uart_core.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c index b4369ed45ae2d..bb25691f50007 100644 --- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c +++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c @@ -1257,19 +1257,14 @@ static void cpm_uart_console_write(struct console *co, const char *s, { struct uart_cpm_port *pinfo = &cpm_uart_ports[co->index]; unsigned long flags; - int nolock = oops_in_progress; - if (unlikely(nolock)) { + if (unlikely(oops_in_progress)) { local_irq_save(flags); - } else { - spin_lock_irqsave(&pinfo->port.lock, flags); - } - - cpm_uart_early_write(pinfo, s, count, true); - - if (unlikely(nolock)) { + cpm_uart_early_write(pinfo, s, count, true); local_irq_restore(flags); } else { + spin_lock_irqsave(&pinfo->port.lock, flags); + cpm_uart_early_write(pinfo, s, count, true); spin_unlock_irqrestore(&pinfo->port.lock, flags); } } -- 2.40.1