Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1392740rdb; Fri, 1 Dec 2023 15:36:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnNc4qdMD28f2+tqMxDU+R4VWZan+n0t1z6mcWluJYWDw5l0SUnjPYRUx8DMc7r5tm+S+T X-Received: by 2002:a05:6808:256:b0:3b2:ef9e:45af with SMTP id m22-20020a056808025600b003b2ef9e45afmr369070oie.13.1701473774661; Fri, 01 Dec 2023 15:36:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701473774; cv=none; d=google.com; s=arc-20160816; b=IritOquS/mgW7BTIQKgnLDmkQd2ciwgO2n0JOe8rBVbSqSRzMzbKonFBx2Grn3Mb/4 5seXvVzSEnRD7+dcllYTTizU6ISJDKbdhtGM9QvpLNDUGvodChaFGCVpkvoTdLy7XTS7 n9rXf86LeB2PkqZBmIfgKesYq47EriYH4ZP+qnWxAw/yOEw6UYN3mb3OswI2MtRqN+t4 Cz87VWd3IwJqlvM0vhru8T2R8OutgtKVER7psjHm+QBaqE1Xb5eFyzDmI+E5g6UDmTDi Q+69714Q77k0lqXp+T42iYlHsGntmIRAUTOcVdjOVfU3WmLDDSzOwvZwLKXt913CI2mg 6sPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GqmfDA6O54prcJnxC3J6dq1u6qKHwn493IjE704DgVU=; fh=N6R5wEpBFr9YaHzZQ5Akr7uXrWCnaV6WUrcB7z0Cr0o=; b=JFGuOp4feURJ9JrHg+OU1g+X2QzKqeajxP9yOf+NUGWQ9T6A5jDG6JOjKVt2l/411x /HAj4mFQS1YTF5ONElmCY2GhG6Rm9NxSmhXcHfuN+lpvIjRO7qz+/MwuVfYhqw+FtnkX V235/sxAaF1ZM855sJRon5C5xQhp4PfC35R5oeqkYJiIeKvHXNbegCISWtB+/uyiompj 8Pqs6aCa2HFhtIKOT7qBfg4vbj4dR06RXXzUEstE4lY6pHoQ9fHY890cOsFbCSgL2NWg EIm5uBCbH6+dVIlXGMbp6vjUpyXmj7MuZw7Xzz6dutdutQDIywSQR7cjMhX0zXCGY6/Q leMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QRiX0Ti0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s3-20020a056a00194300b006cb63c86cc2si4076036pfk.100.2023.12.01.15.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 15:36:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QRiX0Ti0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id D0107807C861; Fri, 1 Dec 2023 15:35:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231311AbjLAXfP (ORCPT + 99 others); Fri, 1 Dec 2023 18:35:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbjLAXfO (ORCPT ); Fri, 1 Dec 2023 18:35:14 -0500 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E24B71B3; Fri, 1 Dec 2023 15:35:19 -0800 (PST) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-58d521f12ebso1567151eaf.2; Fri, 01 Dec 2023 15:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701473719; x=1702078519; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=GqmfDA6O54prcJnxC3J6dq1u6qKHwn493IjE704DgVU=; b=QRiX0Ti0fvhNHVBNPlFx99AmOhxJAr/455TBI+33JmpktjoEiQLmAndu6JycvREqSQ HN1co6/2z6iw64j2VJLY6QtCI0+qQtz4X0Querfv9SfAHoKrTTtJp4jYM7ZEwp5UiUnN 8Vcxi/Od90WE+KwIcLI6v8Uhui3GqCckiU2sJcAa1FFqsRHkkeMvzh60bZKCbqOx8khw 3kJu5rEvGjQIqicSPhg40JdMjbosMmVfOJnKe9D2yKcyu1kmB47LdkCnjWOmNFukSlz/ RVBtDxBbcOKTsyggXpNflLIUCaHEFmGzCw5jcT6m1ftLdokJ5XgA2s1yb8/2raHTg4zk 7a5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701473719; x=1702078519; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GqmfDA6O54prcJnxC3J6dq1u6qKHwn493IjE704DgVU=; b=Wpl0Fj5anQ3XAyUMtPKOMH8CUVamK6VQZSJaSZiTFF9R8/A5WPZSTeaQaIP5TdN3Y7 9ueIZl7h9xfT3L785StMDxAdI/jypOmxCXRyCSGUhIzRw2Ac5jLLaKx7bHA2S+roBJDS yNic/F2t0w6PvAX5SCor5aX+f7IqrJtCrUSjRddoXoYFtsfT55hUi/mCdGNdCt+SA4Cn +kOn63nhOkZlJ3oJIxWhHO2HrZDyZbKt7TNZ2aozOKpK8TFQpjGiccSSFYO9O2SgvfoI rjro1DhNWX+AfFT7SyyRBfEzJP+di3ssLSYCKr+E61BKUGWkMpWjy+bEj4aILd79rpsF QKuA== X-Gm-Message-State: AOJu0Yw6jliTm/X1gAlyGdhiN/yDygomPZqDv5IwdiW6vmKzBqpP7AS9 8G3ilXeIM+wSqTpjm/DmyXtrlexKq5I= X-Received: by 2002:a05:6358:8806:b0:16b:fbd6:9bab with SMTP id hv6-20020a056358880600b0016bfbd69babmr383162rwb.32.1701473718998; Fri, 01 Dec 2023 15:35:18 -0800 (PST) Received: from google.com ([2620:15c:9d:2:1900:8815:33a8:c99c]) by smtp.gmail.com with ESMTPSA id 5-20020a17090a018500b00283991e2b8esm3983361pjc.57.2023.12.01.15.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 15:35:18 -0800 (PST) Date: Fri, 1 Dec 2023 15:35:16 -0800 From: Dmitry Torokhov To: Marcus Folkesson Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] Input: pxrc - simplify mutex handling with guard macro Message-ID: References: <20231201-pxrc-guard-v2-1-714779672bc8@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231201-pxrc-guard-v2-1-714779672bc8@gmail.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FSL_HELO_FAKE, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 01 Dec 2023 15:35:27 -0800 (PST) On Fri, Dec 01, 2023 at 02:17:13PM +0100, Marcus Folkesson wrote: > 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; Now that we are not returning "success" and only carry error codes in this variable we should call it "error". > > - 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; return -EIO; > > - mutex_unlock(&pxrc->pm_mutex); > return retval; return 0; Thanks. -- Dmitry