Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1020054rdb; Fri, 1 Dec 2023 05:13:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9/mybDGys9qd1NB9CdZj4r9PrlkduedR0iDIz1qH/7PcGHh56BujGXTmXbowd3oKM++Fu X-Received: by 2002:a05:6358:4407:b0:16d:f143:55ec with SMTP id z7-20020a056358440700b0016df14355ecmr28880040rwc.18.1701436421096; Fri, 01 Dec 2023 05:13:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701436421; cv=none; d=google.com; s=arc-20160816; b=VVxgEjGdGUc/QHgtHbwpoSqemBKmxhoSVG6N9WGD1U9CqmlBZrNhlRmIAmK3jXhPsT 6HM+Rja5g3zSXR2wkZ+gf/jkTGh3SZN6yMxvij93Ad0nTLVsBfbEXS+A55T6EmzGjSRU KAu982g9xIYIBhUZgrln3vzrYvOtiTL5rTetZ4ERQgpeSzyBiTrJ9DepeNs3HqhKAOD+ VIjjkNhSjPaaN3DyPc1UjUfl+WJ0ffogSJiZqjUjqtyakDgdWwguKH9Rr22wCFN3DpcT 8TRR3LoN8otrsBsMGi0buTdpSSzjCwiy2S5hH8zMYSpzdJo0xzl9ts+5wnbL23rmhVZ3 z9Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=AjyqWLSmP05fxX/Y2CUMDmYvLGb7hv9oWylOkZNdwF8=; fh=WF5JGYxpIVbGBjD7GXr/1vtoD85NABD+7jLkLnlYShY=; b=b0VnQDd3Bopkqx33U/vhO3YchHPidTCC6d/SqdXScx1OLEB9qsSdRhVw4ZvqQ/8UqT C0kdVwedIWGsX7MLAKgFHAzbj3+nSeX7BqpuMd+2zBno5s8vLHJSaobDdNvhMoXOaMZf KsSE5v+ijspefNosvn4kH8VHbwhLfSLcRb/hFDTF/509DefcHIGL8BQEnzSS+zxJHxF0 cuZv4zRi7E12yIcuMu8i9jKewnEIc0lk3ENVZhEl6eWA7KWXgk0PpkiKghelAoQCtihk OhhB5QaAz8GpNDhNYZAMDlYM1jycVi3MdluLOSJ6Yl2VD1pG7uLbOz9m6PLf06wBynk+ 9h9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=b7rURTol; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q197-20020a632ace000000b005c625b9f61esi3163446pgq.779.2023.12.01.05.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 05:13:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=b7rURTol; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id F38C180879FB; Fri, 1 Dec 2023 05:13:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378934AbjLANMy (ORCPT + 99 others); Fri, 1 Dec 2023 08:12:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378922AbjLANMx (ORCPT ); Fri, 1 Dec 2023 08:12:53 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9278710D; Fri, 1 Dec 2023 05:12:59 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-50bd8efb765so987389e87.1; Fri, 01 Dec 2023 05:12:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701436377; x=1702041177; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=AjyqWLSmP05fxX/Y2CUMDmYvLGb7hv9oWylOkZNdwF8=; b=b7rURTol3Ty6IQWmeHGYk+DXRPBDXyodjNySTVVN7pbYTI+QqDw8wGOySYdD354ns+ bD9EDvbmXLrgJQg6TTAq+LVz90Qo/UQs5N8XgnO3LJKSResFBdalAUfD4H7l7gaE96OB XuPSZF92K8i8HBjUtd8xqyK39SrzVbkE/dfTPkhVwYwSCsk+xiik6gXZf76WyaAmKRMG Oyvm5bKRL9h4GwBqWDultCVUAei6wBMMV+voxsKOJVt4fNUQCLi/q22fFKexd5O5ObT4 sT8VYR6m+fFLXj596U3AQz8BF++uzWKZc0sAnslCIg6vKJu8FOVHoGMw3ngycqFUDDtW DJgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701436377; x=1702041177; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AjyqWLSmP05fxX/Y2CUMDmYvLGb7hv9oWylOkZNdwF8=; b=BH2cH135Wlg7vQT+Vwi02k1PZo94KPiV28TDDlizN7zCKZwwsoXi/j8LzVotfFJ9X/ 8UlmtA2kYi2oLrulGR6Mjsd2lyhE0672ickf/ZdMuuxyy42qpBKh05ucelbLtJhpeSDg GCf1uIYTAk4lWewAXMlsdBOj0y4Sav4jV2T/kx2sCghb/traubAkgMaLGgvbWcAMilci +eE4F4pf/ubOz/iWFW56u3egtWFEiJTDUVNSWya+sYyVw+kEaEc36DKpiymws4nMegBd G4Okg/VNShzLKykxIyHOiPrgT29IaIL/kNRDFIB3WYW4IHn0dMIRsmYW8LkoMA1x0Crq rhBg== X-Gm-Message-State: AOJu0YzTPJUF7OAFyUtHXX1sTQMrmTw3UUgGlfQXeEfE/eaPRMjVgNB2 DGGl6UkP14wQvJQCnlfYdlpiAU95oFY= X-Received: by 2002:a05:6512:23a5:b0:50b:c3b9:76e1 with SMTP id c37-20020a05651223a500b0050bc3b976e1mr776137lfv.37.1701436377106; Fri, 01 Dec 2023 05:12:57 -0800 (PST) Received: from [192.168.20.11] (83-233-6-197.cust.bredband2.com. [83.233.6.197]) by smtp.gmail.com with ESMTPSA id v26-20020a05651203ba00b00507a66f747csm420907lfp.30.2023.12.01.05.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 05:12:56 -0800 (PST) From: Marcus Folkesson Date: Fri, 01 Dec 2023 14:17:13 +0100 Subject: [PATCH v2] Input: pxrc - simplify mutex handling with guard macro MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231201-pxrc-guard-v2-1-714779672bc8@gmail.com> X-B4-Tracking: v=1; b=H4sIANjcaWUC/23MSw7CIBSF4a00dywGuClUR92H6QAB6U3sI6Ckp mHvYscO/5Ocb4fkI/kE12aH6DMlWuYa8tSAHc0cPCNXGySXKCQXbN2iZeFtomMcncVWa3FHBfW wRv+g7cBuQ+2R0muJn8PO4rf+ZbJggmF3Qe1Vq1F1fZgMPc92mWAopXwB41haGKQAAAA= To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Marcus Folkesson X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2831; i=marcus.folkesson@gmail.com; h=from:subject:message-id; bh=Io5ea7Dmw9B+JcwG48J2CQVafp3mDV/lXy5QHkwQuNQ=; b=owEBbQKS/ZANAwAIAYiATm9ZXVIyAcsmYgBladzkuMQ7IbZDJlFR+Aw0hV2XtiuCQiDvOQ0qX YnATZp6f4+JAjMEAAEIAB0WIQQFUaLotmy1TWTBLGWIgE5vWV1SMgUCZWnc5AAKCRCIgE5vWV1S MmSqEACZIuTuuXzVNkoEkDoDYoDotXDzrQVuA6cp+wBPHN23lQcCQytOfEiE4A2jMk4r7czQcSx jLdzJbjNLA8hB7mjSSgmCpjefBZDxKbS52gMWmRQav0yOXCM/7xjxsESbCl9Oa4iimT9GLHEwdq LDjbJjc7IKxxRpPi+2ofsLQZmnjhECvJA2Ieu0O5xJxPfMrFuI0eTc5dzyriUhPiCjKtFsXdgXz NN+i62xSa29k9k+pLHuQnd0DTVLyBYC08KILyq7f/lytoqdrtP9RwB518xaxcy/cWciZKhPob3n 83RzttjQrPwX21q2CViMRKOpRXpfKMqMvMmK03ZqmdHKikbHaOlyEYla8LeSCvGNCpoB+/Ono15 KG+OVlgCncJTd7orHceYt+NE1Igm03T7mSqyXnBmULMrgVWG7UuCJ20DBf5lRelgrwoy6hiBJXA s9He1TBi+rl0j59h4HP47aPhtkeHP7NV6/P/pvm6cYAJBdDzhIBsD5nowKcuDPqSsi8njBn26NF ZGFCbGIEd3o6q0h2LYF4JbkcPZpsKRhZ0sE/bRbNq/VxtPRuhWhcwm9+p0p6h0vBCXyBv3206sn set+QQ+4uj8Eh8LrDbGr6GTjbZQTe21vxmisYwC5+8aQxXZuUtMB7xvrFAP/VcUNnXIDzDpk96a A8fhEVHZMrVsnGQ== X-Developer-Key: i=marcus.folkesson@gmail.com; a=openpgp; fpr=AB91D46C7E0F6E6FB2AB640EC0FE25D598F6C127 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 01 Dec 2023 05:13:19 -0800 (PST) Use the guard(mutex) macro for handle mutex lock/unlocks. Signed-off-by: Marcus Folkesson --- Changes in v2: - Add guard in pxrc_open() - Link to v1: https://lore.kernel.org/r/20231201-pxrc-guard-v1-1-38937e657368@gmail.com --- drivers/input/joystick/pxrc.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/drivers/input/joystick/pxrc.c b/drivers/input/joystick/pxrc.c index ea2bf5951d67..d4b699418361 100644 --- a/drivers/input/joystick/pxrc.c +++ b/drivers/input/joystick/pxrc.c @@ -5,15 +5,17 @@ * Copyright (C) 2018 Marcus Folkesson */ -#include +#include #include -#include +#include +#include #include +#include +#include #include + #include #include -#include -#include #define PXRC_VENDOR_ID 0x1781 #define PXRC_PRODUCT_ID 0x0898 @@ -83,31 +85,26 @@ static int pxrc_open(struct input_dev *input) struct pxrc *pxrc = input_get_drvdata(input); int retval; - mutex_lock(&pxrc->pm_mutex); + guard(mutex)(&pxrc->pm_mutex); retval = usb_submit_urb(pxrc->urb, GFP_KERNEL); if (retval) { dev_err(&pxrc->intf->dev, "%s - usb_submit_urb failed, error: %d\n", __func__, retval); - retval = -EIO; - goto out; + return -EIO; } pxrc->is_open = true; - -out: - mutex_unlock(&pxrc->pm_mutex); - return retval; + return 0; } static void pxrc_close(struct input_dev *input) { struct pxrc *pxrc = input_get_drvdata(input); - mutex_lock(&pxrc->pm_mutex); + guard(mutex)(&pxrc->pm_mutex); usb_kill_urb(pxrc->urb); pxrc->is_open = false; - mutex_unlock(&pxrc->pm_mutex); } static void pxrc_free_urb(void *_pxrc) @@ -208,10 +205,9 @@ static int pxrc_suspend(struct usb_interface *intf, pm_message_t message) { struct pxrc *pxrc = usb_get_intfdata(intf); - mutex_lock(&pxrc->pm_mutex); + guard(mutex)(&pxrc->pm_mutex); if (pxrc->is_open) usb_kill_urb(pxrc->urb); - mutex_unlock(&pxrc->pm_mutex); return 0; } @@ -221,11 +217,10 @@ static int pxrc_resume(struct usb_interface *intf) struct pxrc *pxrc = usb_get_intfdata(intf); int retval = 0; - mutex_lock(&pxrc->pm_mutex); + guard(mutex)(&pxrc->pm_mutex); if (pxrc->is_open && usb_submit_urb(pxrc->urb, GFP_KERNEL) < 0) retval = -EIO; - mutex_unlock(&pxrc->pm_mutex); return retval; } --- base-commit: ffc253263a1375a65fa6c9f62a893e9767fbebfa change-id: 20231201-pxrc-guard-03dc35771b36 Best regards, -- Marcus Folkesson