From patchwork Sun Aug 25 05:16:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776694 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 A302DC5320E for ; Sun, 25 Aug 2024 05:31:05 +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:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j9zYR0W/Xjhx97slmPTim4xkiDUhOUV5BM1jCImN77U=; b=yy5OfHmcTy4fLclF5xy6dsthYk WJ5JJn9dv/wzswdz8Th/WBOjlnX9WNtb680K+idfXKBKc011WhbNQaroSXh5hFxUJ6Ewb1ztS8z/8 QEhMlmyA/8F2nffrCDj2JG69qwPvJrkE7CvApsR6z4VcExh2nC4EBXmq93UuGaj5UsQx9A/cgcUfz ffysrExWv/wRs+yw/FZz9xXv3M/aidB3xl5DDn3722I+WBXizA6L5DSZzd7ol8dB1dFK9YAn0xci8 XJHp9ru2x2FKgORh1IdckUV+i5n5kqHfy5kfMb6erdcZnA1QY6YkrCNHV4h4rFM3hx19ID/bDV5qM OdgeZNGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5q2-00000003hHR-0Cz2; Sun, 25 Aug 2024 05:30:54 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cU-00000003dis-1xID for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:56 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-7143165f23fso2467551b3a.1 for ; Sat, 24 Aug 2024 22:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563013; x=1725167813; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j9zYR0W/Xjhx97slmPTim4xkiDUhOUV5BM1jCImN77U=; b=PlYfcL5YLj/uQWPPpAzuF29113bV3alSluwR7wxFdgzQURz4V/l44AC7PUMxIXmtOp 1sgGKzkJlGBXyOYZV9Pjlk1dDDigIcfN2l///JswfV7hsx2l1TloqQBDJ9Es5QvxaUGg anSTTuyfnMwl3qx2dHE8s0aZkR7CdXRpXsRA+6xJoJD9dJOkZVAKFCeZtnW98wDnmVGN G3h7sXiJXAUa37Gq1G6RIfqwtEY77yiSOnRPjHFg8NtscX4SwJmRrGYHGs3lrLBZmRXn QSQK4WJF5pLrMRKCsJAJWQA/DaGwOg1aVwrcHojJKjhXB/4HaV3VpbK43FbFxgdmnNvx qLxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563013; x=1725167813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j9zYR0W/Xjhx97slmPTim4xkiDUhOUV5BM1jCImN77U=; b=ql/QzfAUhG5JERnxfZpRd02VCzVHHb17rCCXXFCe1VhCJYWEMmBM/ZWZQSBUbqeTxa +dC2qyj5IRY+oFspYbgi+A40yD5D/nS+wpuByYEoCPLVbPbrXkoCH4JxSf7cvj+UkePB E0DHppmpjp+MFdehskidv4YSUTFtAqqYFYKBTr0PTWhypmShR838ynIgIkLRKWW5dS/S STflWF9/JUkDZdxsZUcX1GZineLFMfJVpsRLrr96S38jyEJSxZ/NFNWWuE0lsbJ5uRC4 Si/reel0lCFJ6Qd1krIVpusgL6A4EbYp+JNnT5R804XovSuNQH6k5R+wSqE79oEh8bfm l5/g== X-Forwarded-Encrypted: i=1; AJvYcCU8BKhhR82QI59w7WX3ZUGvU9thJFhx2/2FHq1kZWgzd2u+1kA7NN+jbE8wLSkyAFiQq2eiQu8CTtwiNL615mNw@lists.infradead.org X-Gm-Message-State: AOJu0YwUb0fZu+AKd1sG2eLY5EPShRPXad7P0cGm1rDDw7nfmvloxjrH Fgs3dHYJe71IbQD6f3FJUFvK1XcgpLcoQHrdDhj/PlqD6OJIozBx X-Google-Smtp-Source: AGHT+IHcuT4NA41j3BiOlgdyA7A3m2CkwtxDOGLO51Pqdelg8y5qs9HsGoezNmvzuRmb2+38RG5t8A== X-Received: by 2002:a05:6a00:18a1:b0:70e:8e3a:10ee with SMTP id d2e1a72fcca58-7144587e2dbmr7640487b3a.21.1724563013105; Sat, 24 Aug 2024 22:16:53 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:66dc:ce07:b7cc:51ea]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ad55a94sm5622442a12.57.2024.08.24.22.16.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:52 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Shawn Guo , Sascha Hauer , Fabio Estevam , Laxman Dewangan , Thierry Reding , Hans de Goede , Tony Lindgren , Jeff LaBundy , linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org Subject: [PATCH 11/17] Input: matrix_keypad - use guard notation when acquiring spinlock Date: Sat, 24 Aug 2024 22:16:15 -0700 Message-ID: <20240825051627.2848495-12-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog In-Reply-To: <20240825051627.2848495-1-dmitry.torokhov@gmail.com> References: <20240825051627.2848495-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240824_221654_571336_511E2A2B X-CRM114-Status: GOOD ( 12.23 ) 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 This makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/matrix_keypad.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 7a56f3d3aacd..bd763d704306 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -158,18 +158,17 @@ static void matrix_keypad_scan(struct work_struct *work) activate_all_cols(pdata, true); /* Enable IRQs again */ - spin_lock_irq(&keypad->lock); - keypad->scan_pending = false; - enable_row_irqs(keypad); - spin_unlock_irq(&keypad->lock); + scoped_guard(spinlock_irq, &keypad->lock) { + keypad->scan_pending = false; + enable_row_irqs(keypad); + } } static irqreturn_t matrix_keypad_interrupt(int irq, void *id) { struct matrix_keypad *keypad = id; - unsigned long flags; - spin_lock_irqsave(&keypad->lock, flags); + guard(spinlock_irqsave)(&keypad->lock); /* * See if another IRQ beaten us to it and scheduled the @@ -185,7 +184,6 @@ static irqreturn_t matrix_keypad_interrupt(int irq, void *id) msecs_to_jiffies(keypad->pdata->debounce_ms)); out: - spin_unlock_irqrestore(&keypad->lock, flags); return IRQ_HANDLED; } @@ -209,9 +207,9 @@ static void matrix_keypad_stop(struct input_dev *dev) { struct matrix_keypad *keypad = input_get_drvdata(dev); - spin_lock_irq(&keypad->lock); - keypad->stopped = true; - spin_unlock_irq(&keypad->lock); + scoped_guard(spinlock_irq, &keypad->lock) { + keypad->stopped = true; + } flush_delayed_work(&keypad->work); /*