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 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 07542C5321E for ; Sun, 25 Aug 2024 13:11:55 +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: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=u5HPuabIgkyx2GqHJrYxVWzQ9JtdHpCasYdEjisxJKo=; b=Hxyl/xHYPh8gOaL7xaLIiyET0j nbEKcnI1KYwqSIFb6Q2ze7T8lIilRhnzYGW+hqnxGuhq0idppnprdnrzQczG8jHfe9p76bzv1thex SyNYWFSo38mgyEMM+4xk6slThlzDqbBb+UyKdccq89hM+mQVkrtEpP0bER20BPns/pKw172LTwD2M uAQZemIRcpNsKUmK+1a9qpWQNMLcRWNeY6MjPfduEOTW1YaFBJDSHDxWRBlTD2bP5vYc9ZU7SLkPF 9b0glnfHDF1IlQzdmsYpzsZvIT+N2RjHnZwdIryRfpOkfy+1aJyb3DUg8n726XHQLQAPlpunZ5fEC 06QQmcRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1siD1x-00000004MTV-31dT; Sun, 25 Aug 2024 13:11:41 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1siD18-00000004MCT-38wO for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 13:10:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724591448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u5HPuabIgkyx2GqHJrYxVWzQ9JtdHpCasYdEjisxJKo=; b=GtsD6BWPUetXAT/kd/ERI49JTLgcDIjvFcRHKrF2Y2onodGLiWyTTXbCPcX7HkPAQpSlNc FKA7KNSHdQNpAN4fokuqxMYwpJZMJ3LgaOE/VpTCaI/z4VkWiHflq1t/Y3X1yNnoN7p7r/ 91K4UbpIDCLq4bFvUChAEz79ANdYtXs= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-63-RkJc6fyRNhqbpvbzHtGZ3g-1; Sun, 25 Aug 2024 09:10:46 -0400 X-MC-Unique: RkJc6fyRNhqbpvbzHtGZ3g-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-5334844dcc5so3210746e87.0 for ; Sun, 25 Aug 2024 06:10:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724591445; x=1725196245; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u5HPuabIgkyx2GqHJrYxVWzQ9JtdHpCasYdEjisxJKo=; b=hTWDYkeBuWE1FEqhmxFvETvbKBTiAOHLIM8S0R0L6lJtBrI87nMlCluy8nAcieD87j 0jEbiH3KRpCJKuyE4YyVsPzvkKWOwUPppKwTR1vt4APKiSB50RRxH7TewfLTisk3X6z+ 2xqcFBCE64zbVIFKGqz3BTGRY0f7BNAmOWT0tDkLOnCADmPlYxWkDvN235hgP7yWojsG ibrUGmaAlWotKpeorpTw8y3WhjLuOyolZUmUF3XSUuDF1uKmKvbojoiAM8oiezIfLkTU wGmMJS/CB2zL8uQEPmKmUHkY9TpZXD0ukZoyza9taRHXKh2dcxUg3r3EcIEt/xwLAlm1 74Kw== X-Forwarded-Encrypted: i=1; AJvYcCU4utN2xh/hljivHzac+j5AJVd3B4ekYNsHwtZjwli9JqAOKg7X8ZilZFFfjXdBIcxNrZ3vDqMziY4OKS4hWvE2@lists.infradead.org X-Gm-Message-State: AOJu0YzUTC73thlyozR/Ok6L2Ow63RxBGZZVeAWuJknR31QHA1kv6RvP YDwmdvvrjSjeSzAp4cghHl0IuEM4IHGxWd0Q6K7ZevkCqn1TPlKx8bnOmX8WHkZF4ugXq0Zt6rX oLAtJLP8PJI+FuiGDMhu+mngl81dRupCrJQkq8H2g+BXq/PueoaJ13dbNueuK9Iw7PghnR/yb X-Received: by 2002:a05:6512:2814:b0:52e:9ac6:a20f with SMTP id 2adb3069b0e04-534388610f5mr4667340e87.37.1724591444711; Sun, 25 Aug 2024 06:10:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFyq3crzju8WROi3/9aXixWRhW7fyntueq+5N6z4YHdvwe29s5TLxrye+t2/cfTKoEIxN6TcA== X-Received: by 2002:a05:6512:2814:b0:52e:9ac6:a20f with SMTP id 2adb3069b0e04-534388610f5mr4667316e87.37.1724591444076; Sun, 25 Aug 2024 06:10:44 -0700 (PDT) Received: from ?IPV6:2001:1c00:c32:7800:5bfa:a036:83f0:f9ec? (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a868f29a4c7sm536588766b.65.2024.08.25.06.10.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 25 Aug 2024 06:10:43 -0700 (PDT) Message-ID: <0e8ae323-d6c7-4460-a342-85e52ce0c1ef@redhat.com> Date: Sun, 25 Aug 2024 15:10:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 05/17] Input: gpio-keys - switch to using cleanup functions To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Michael Hennerich , Shawn Guo , Sascha Hauer , Fabio Estevam , Laxman Dewangan , Thierry Reding , Tony Lindgren , Jeff LaBundy , linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org References: <20240825051627.2848495-1-dmitry.torokhov@gmail.com> <20240825051627.2848495-6-dmitry.torokhov@gmail.com> From: Hans de Goede In-Reply-To: <20240825051627.2848495-6-dmitry.torokhov@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US, nl Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240825_061050_923712_5A80E2B5 X-CRM114-Status: GOOD ( 23.34 ) 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 Hi, On 8/25/24 7:16 AM, Dmitry Torokhov wrote: > Start using __free() and guard() primitives to simplify the code > and error handling. 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 and all allocated > memory is freed. > > Signed-off-by: Dmitry Torokhov Thanks, patch looks good to me: Reviewed-by: Hans de Goede Regards, Hans > --- > drivers/input/keyboard/gpio_keys.c | 44 ++++++++++++------------------ > 1 file changed, 17 insertions(+), 27 deletions(-) > > diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c > index 9fb0bdcfbf9e..380fe8dab3b0 100644 > --- a/drivers/input/keyboard/gpio_keys.c > +++ b/drivers/input/keyboard/gpio_keys.c > @@ -245,23 +245,20 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, > { > int n_events = get_n_events_by_type(type); > const unsigned long *bitmap = get_bm_events_by_type(ddata->input, type); > - unsigned long *bits; > ssize_t error; > int i; > > - bits = bitmap_alloc(n_events, GFP_KERNEL); > + unsigned long *bits __free(bitmap) = bitmap_alloc(n_events, GFP_KERNEL); > if (!bits) > return -ENOMEM; > > error = bitmap_parselist(buf, bits, n_events); > if (error) > - goto out; > + return error; > > /* First validate */ > - if (!bitmap_subset(bits, bitmap, n_events)) { > - error = -EINVAL; > - goto out; > - } > + if (!bitmap_subset(bits, bitmap, n_events)) > + return -EINVAL; > > for (i = 0; i < ddata->pdata->nbuttons; i++) { > struct gpio_button_data *bdata = &ddata->data[i]; > @@ -271,12 +268,11 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, > > if (test_bit(*bdata->code, bits) && > !bdata->button->can_disable) { > - error = -EINVAL; > - goto out; > + return -EINVAL; > } > } > > - mutex_lock(&ddata->disable_lock); > + guard(mutex)(&ddata->disable_lock); > > for (i = 0; i < ddata->pdata->nbuttons; i++) { > struct gpio_button_data *bdata = &ddata->data[i]; > @@ -290,11 +286,7 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, > gpio_keys_enable_button(bdata); > } > > - mutex_unlock(&ddata->disable_lock); > - > -out: > - bitmap_free(bits); > - return error; > + return 0; > } > > #define ATTR_SHOW_FN(name, type, only_disabled) \ > @@ -470,11 +462,10 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) > { > struct gpio_button_data *bdata = dev_id; > struct input_dev *input = bdata->input; > - unsigned long flags; > > BUG_ON(irq != bdata->irq); > > - spin_lock_irqsave(&bdata->lock, flags); > + guard(spinlock_irqsave)(&bdata->lock); > > if (!bdata->key_pressed) { > if (bdata->button->wakeup) > @@ -497,7 +488,6 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) > ms_to_ktime(bdata->release_delay), > HRTIMER_MODE_REL_HARD); > out: > - spin_unlock_irqrestore(&bdata->lock, flags); > return IRQ_HANDLED; > } > > @@ -1062,10 +1052,10 @@ static int gpio_keys_suspend(struct device *dev) > if (error) > return error; > } else { > - mutex_lock(&input->mutex); > + guard(mutex)(&input->mutex); > + > if (input_device_enabled(input)) > gpio_keys_close(input); > - mutex_unlock(&input->mutex); > } > > return 0; > @@ -1075,20 +1065,20 @@ static int gpio_keys_resume(struct device *dev) > { > struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); > struct input_dev *input = ddata->input; > - int error = 0; > + int error; > > if (device_may_wakeup(dev)) { > gpio_keys_disable_wakeup(ddata); > } else { > - mutex_lock(&input->mutex); > - if (input_device_enabled(input)) > + guard(mutex)(&input->mutex); > + > + if (input_device_enabled(input)) { > error = gpio_keys_open(input); > - mutex_unlock(&input->mutex); > + if (error) > + return error; > + } > } > > - if (error) > - return error; > - > gpio_keys_report_state(ddata); > return 0; > }