From patchwork Sun Aug 25 05:16:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776683 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 5B743C5320E for ; Sun, 25 Aug 2024 05:23:51 +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=1eSvY1Wrp9wBfC4UTCsKK6UuziOLVmjJl+zbNYuZ+vM=; b=GoFcKPxrZ/LdYaUdkf6fonxV7B 7mld0XX4jSLVdpgDmWkeU2u5wVULuLJCL0MopRMez/Lij8njJ8q48QYzzM4odGBIp4nNx2Ol2djd5 jRZ2pypVHkehxQyCW0dD0wcfDGUr1r139s3rmZznCJN1SRpYNCgcrMe8xEDLMbShHckd9VVZDqCE1 mTpj/MZYx/bFnBYcQOR1lhuA4x1Fd4YEwcKo9gQUXCBZipiPng8uqieJ86MPQTnV4LE9KsxdiNG86 aivKjA78d3yBCEwpfsPIwl65xAOq4H8KDcKQtTbed0VSpL5jvzvciKQRnYb3wzifLrzck+fryxsZV moYPXdGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5j4-00000003fea-0EgL; Sun, 25 Aug 2024 05:23:42 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cP-00000003dft-1Ebh for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:50 +0000 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-70940c9657dso2546573a34.1 for ; Sat, 24 Aug 2024 22:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563008; x=1725167808; 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=1eSvY1Wrp9wBfC4UTCsKK6UuziOLVmjJl+zbNYuZ+vM=; b=QNepyJBsb+CpgBF629sZBePGj2y+ngvB9A5dQwxrkPgqdaLDHlFcTKLkpNjQA0hrVu MyVyAaSnUbI7EAVjFabs+7JcrNonhRA8e0r/BMSu7m+hdLmHiJIU6N71dXV0WNK/Gh61 UpL7UD1xfvbvPAP3YVM9HIiU0d3apaArhVMGibgxORiuzkJXbnDnWffxESAoXNx6cuQR 3f5G9qW8JoObAKQig6/3Z899WnSzNFFZwNpNFT6RO+PVagvzl6M8kcAbpv3K93NvOkip bTmORaFnE2cZcIjxF+CP0926PSwMptnxlqPyBwcUcfoA+g0RVYbsnuC9+3UNyYq6I2jo gjJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563008; x=1725167808; 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=1eSvY1Wrp9wBfC4UTCsKK6UuziOLVmjJl+zbNYuZ+vM=; b=Hgs04/cTWNzkg/Ljvu30nFQPJcQrD+8RcxsFnHTBPiogAi8k7DcfgaTEKLVTNSS+hc A6MF/+QVBJmPvxgR0TTiHipdz1oEMtA+3UekkVbH/Yg0QWlX+YzDTZqoxCIP1T5/R0k3 19xBEykBXov2VZxwTiPeA2sxyCsep0b2wzFf9+oRZvK10mCEeBzWKWpI9SxHExRvEBqJ ZSNTMo9xpfJfp+T0V6dgqcpgYuFzulByDDT0YkqWDd8T55UT9+zMpz2wH6qjgk51AhRw kc5HkZEI9dhSDnCvfuRpBbYvb/uwwQ960eHvMEeT/MegwvEr3DCjunrLLYoRt4LnOIp5 FtHA== X-Forwarded-Encrypted: i=1; AJvYcCWKV3y5+ZMlO/pdkF0RniBFI4DFeQYY7y2ocvt9V+0bpWCFuoKrXad966BK6qnfCK1/ZfN96HBpwLtdW0rBFWbO@lists.infradead.org X-Gm-Message-State: AOJu0Yw76ZiFIGanJPDZ5ZWFTr2cqn6YEHlQ6pW4dYl90ZzXxAgVUx2b GH0T1YNLsCi6JesHpeX6nuETkj2VS6q+EOdIZZNT5ijrffYRhj3e X-Google-Smtp-Source: AGHT+IFPvL2EwU0HTmfQ3cZEpHTEWkZdGY6KDfx96n7lf7JVGqj+9oNVagIFdpcxgTMQQpdCDsaEdQ== X-Received: by 2002:a05:6808:302a:b0:3d9:2aa5:4077 with SMTP id 5614622812f47-3de2a8735e4mr7831127b6e.5.1724563007948; Sat, 24 Aug 2024 22:16:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:47 -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 07/17] Input: ipaq-micro-keys - use guard notation when acquiring mutex and spinlock Date: Sat, 24 Aug 2024 22:16:11 -0700 Message-ID: <20240825051627.2848495-8-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_221649_358325_C23398A1 X-CRM114-Status: GOOD ( 11.77 ) 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/ipaq-micro-keys.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/input/keyboard/ipaq-micro-keys.c b/drivers/input/keyboard/ipaq-micro-keys.c index 1d71dd79ffd2..58631bf7ce55 100644 --- a/drivers/input/keyboard/ipaq-micro-keys.c +++ b/drivers/input/keyboard/ipaq-micro-keys.c @@ -54,18 +54,18 @@ static void micro_key_receive(void *data, int len, unsigned char *msg) static void micro_key_start(struct ipaq_micro_keys *keys) { - spin_lock(&keys->micro->lock); + guard(spinlock)(&keys->micro->lock); + keys->micro->key = micro_key_receive; keys->micro->key_data = keys; - spin_unlock(&keys->micro->lock); } static void micro_key_stop(struct ipaq_micro_keys *keys) { - spin_lock(&keys->micro->lock); + guard(spinlock)(&keys->micro->lock); + keys->micro->key = NULL; keys->micro->key_data = NULL; - spin_unlock(&keys->micro->lock); } static int micro_key_open(struct input_dev *input) @@ -141,13 +141,11 @@ static int micro_key_resume(struct device *dev) struct ipaq_micro_keys *keys = dev_get_drvdata(dev); struct input_dev *input = keys->input; - mutex_lock(&input->mutex); + guard(mutex)(&input->mutex); if (input_device_enabled(input)) micro_key_start(keys); - mutex_unlock(&input->mutex); - return 0; }