Message ID | 20230216141555.116219-1-brgl@bgdev.pl |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp553942dyf; Thu, 16 Feb 2023 06:21:55 -0800 (PST) X-Google-Smtp-Source: AK7set83EOqVel1eGDHhdrV7lphIzH+O6Y30LOCPsZKK43SqEBZl+fv1dFYy/iT0lQQuMRo/groC X-Received: by 2002:a17:906:b30a:b0:8b1:3b95:cf3f with SMTP id n10-20020a170906b30a00b008b13b95cf3fmr6070585ejz.70.1676557315280; Thu, 16 Feb 2023 06:21:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676557315; cv=none; d=google.com; s=arc-20160816; b=jV/MCUyGI7I/EMHwYtGtckSH3+x9bClo5J7fFmv1aXO497IVXSiyRuAfMlHg/IWXGR yfrpfv7+rlygUJB+/gbyembbtWrsidcT/eCd2zkH3FX8RLSXsULvoiJHNlCNGLnVjk+s aAQR6qchyxKTExWhRmEMB+aG8iv6hUY2OqQ1VmhyJfvwSuWQ3N4MLNsADcqMD3gIf8/8 CZP8viF4wgzobmTNqDan74ta4j5AB51SDvCtq4ppn0LBwC9pEs/3x8kdev8Qhgaw2xT6 8kMrNX+EenkntyEnUmzpQVpL3e+rCFemNHSfIPTI4hPuccnw+mKFUZ87Ut0YB2+XwZ9p fD5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=vHKzG8cIzUJ9myM1y/sRXdNYOKLlG72/XSqg8hiPzrk=; b=rk1L45HmydrbvfE5UwcgoHwv2QovvLmaKHPCzlUfGmcjTNNnl3nik9qhxJiwr0D185 agMGPBE9UG0HoE4qgYsEp0o5UhS5/8kgwZwluCiPka5iXo1NK/roVdIo5JbBzeC6/XD5 e6Z71H8BHZ6vHrNl34CAWwXXW9qI5fzHJNwugdmWiKwbVbNeJr8pzn7ERf611fh9BejH v1dSSZUSgxua70NB2pFk+rTlo4rav0lTNsZUB1XjI90lf1+msRDHcYB9i0Xdlm54zNp4 fdFg0VakYrwTfVO7cvtwp7xDiOsh2pZMkdKAeniIIPGwZDFspXUhpEZwoGqnc8yFxXhw mRcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=EVjVA7YM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id et19-20020a170907295300b008b163745b78si1596652ejc.661.2023.02.16.06.21.31; Thu, 16 Feb 2023 06:21:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=EVjVA7YM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230040AbjBPOQh (ORCPT <rfc822;aimixsaka@gmail.com> + 99 others); Thu, 16 Feb 2023 09:16:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbjBPOQf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 16 Feb 2023 09:16:35 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 470984BE89 for <linux-kernel@vger.kernel.org>; Thu, 16 Feb 2023 06:16:02 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id o19-20020a05600c379300b003e21af96703so566946wmr.2 for <linux-kernel@vger.kernel.org>; Thu, 16 Feb 2023 06:16:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vHKzG8cIzUJ9myM1y/sRXdNYOKLlG72/XSqg8hiPzrk=; b=EVjVA7YMZHaFiNYnlJoUWGMytzMYXIm7RXAlNjSIpWz+U/QvgPJwVcXp4Qp/X0uKXJ aGGnxlBIZZo7cdpIe7nUcd6bjAEP7ppTulsIALxLn3I9vJsW6Zz7OUaOQ06kifl66anT MBYfDtditslrqNGrC0zBF5e7i29xsBkF5O8egKnjOIdOnj6/X2wrGAs4sqfGKqVU3Yur l08WOY80/F9G1non1mgY03KRfDNRqhmEuDAZe1OiVx7o/YiGdgAXQ7OaULvxI1OhbwGl ENYqqV+axebshLrScF2VXH6WagxZKWHo5kwL6ZPEOllv4l7HvsblrBfxAGd1JmFVN5XX SMlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vHKzG8cIzUJ9myM1y/sRXdNYOKLlG72/XSqg8hiPzrk=; b=TfEUtqyIxIkW8PEeur6qgw0i7N1Us4dPhS5DbBMbXFsW0LTsmDhFXdm5yFiswCJB/E AeTrYZk9KtK1XXW+rq1LLzm+aIfCRDCyhKPd4sEvAKPp+uQSxSJdQ/Yg97PHEdBRl/Au +TndeOBHSFbXgSqtBGHr272XZ3s0U3cVAy1xFuM6tZzet2CS2zpHLnGZ2TU4ATJAWppf IVZHUo4AIBDqKtlWOuuOiLrick60dhDGL0V+4Ek2VVllhT0iBHgeWmlNKnOpuTy6UtNu KLdzYNDTOdiX+/KwAz5n6bkGQo/zJaS5eYgwS1mNCFTlKPQPldqfWaaTF1mfGh9l8mGx RbAg== X-Gm-Message-State: AO0yUKX2/D95rnv+ar/CRRJrCmZuUVU34QaQKJE1W3t1cjiVg6cAzJmm +hWISSRmwic2h6V6jxcfM8qTFA== X-Received: by 2002:a05:600c:4d92:b0:3e2:dba:7155 with SMTP id v18-20020a05600c4d9200b003e20dba7155mr2017884wmp.20.1676556960676; Thu, 16 Feb 2023 06:16:00 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:7c5b:1160:db5d:72da]) by smtp.gmail.com with ESMTPSA id ay1-20020a05600c1e0100b003e1fee8baacsm5471478wmb.25.2023.02.16.06.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 06:15:59 -0800 (PST) From: Bartosz Golaszewski <brgl@bgdev.pl> To: Kent Gibson <warthog618@gmail.com>, Linus Walleij <linus.walleij@linaro.org>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, Viresh Kumar <viresh.kumar@linaro.org> Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski <brgl@bgdev.pl>, Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr> Subject: [PATCH] gpio: sim: fix a memory leak Date: Thu, 16 Feb 2023 15:15:55 +0100 Message-Id: <20230216141555.116219-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757997763426188321?= X-GMAIL-MSGID: =?utf-8?q?1757997763426188321?= |
Series |
gpio: sim: fix a memory leak
|
|
Commit Message
Bartosz Golaszewski
Feb. 16, 2023, 2:15 p.m. UTC
Fix an inverted logic bug in gpio_sim_remove_hogs() that leads to GPIO
hog structures never being freed.
Fixes: cb8c474e79be ("gpio: sim: new testing module")
Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
drivers/gpio/gpio-sim.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, Feb 16, 2023 at 03:15:55PM +0100, Bartosz Golaszewski wrote: > Fix an inverted logic bug in gpio_sim_remove_hogs() that leads to GPIO > hog structures never being freed. Ha-ha, I stared to this code, and in the head I was "okay, this loop is until chip_label is *not* NULL, so should be fine". At the same time, "! is hard to process", see for example 2754435d4c82 ("ACPI / battery: get rid of negations in conditions") which I had suggested. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> P.S. But my patch I mentioned looks also good to have, no? > Fixes: cb8c474e79be ("gpio: sim: new testing module") > Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr> > Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> > --- > drivers/gpio/gpio-sim.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c > index 60514bc5454f..9e3893b19e4f 100644 > --- a/drivers/gpio/gpio-sim.c > +++ b/drivers/gpio/gpio-sim.c > @@ -736,7 +736,7 @@ static void gpio_sim_remove_hogs(struct gpio_sim_device *dev) > > gpiod_remove_hogs(dev->hogs); > > - for (hog = dev->hogs; !hog->chip_label; hog++) { > + for (hog = dev->hogs; hog->chip_label; hog++) { > kfree(hog->chip_label); > kfree(hog->line_name); > } > -- > 2.37.2 >
On Thu, Feb 16, 2023 at 3:42 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Thu, Feb 16, 2023 at 03:15:55PM +0100, Bartosz Golaszewski wrote: > > Fix an inverted logic bug in gpio_sim_remove_hogs() that leads to GPIO > > hog structures never being freed. > > Ha-ha, I stared to this code, and in the head I was "okay, this loop is until > chip_label is *not* NULL, so should be fine". > > At the same time, "! is hard to process", see for example > 2754435d4c82 ("ACPI / battery: get rid of negations in conditions") > which I had suggested. > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > P.S. But my patch I mentioned looks also good to have, no? > I don't think it matters. In fact - I'm not sure if the order was accidental or not anymore. :( If you want to discuss it further - please resend it as a regular patch on the list. Bart
On Thu, Feb 16, 2023 at 3:16 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > Fix an inverted logic bug in gpio_sim_remove_hogs() that leads to GPIO > hog structures never being freed. > > Fixes: cb8c474e79be ("gpio: sim: new testing module") > Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr> > Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> > --- > drivers/gpio/gpio-sim.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c > index 60514bc5454f..9e3893b19e4f 100644 > --- a/drivers/gpio/gpio-sim.c > +++ b/drivers/gpio/gpio-sim.c > @@ -736,7 +736,7 @@ static void gpio_sim_remove_hogs(struct gpio_sim_device *dev) > > gpiod_remove_hogs(dev->hogs); > > - for (hog = dev->hogs; !hog->chip_label; hog++) { > + for (hog = dev->hogs; hog->chip_label; hog++) { > kfree(hog->chip_label); > kfree(hog->line_name); > } > -- > 2.37.2 > Applied and fixed the email address used. Bart
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index 60514bc5454f..9e3893b19e4f 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -736,7 +736,7 @@ static void gpio_sim_remove_hogs(struct gpio_sim_device *dev) gpiod_remove_hogs(dev->hogs); - for (hog = dev->hogs; !hog->chip_label; hog++) { + for (hog = dev->hogs; hog->chip_label; hog++) { kfree(hog->chip_label); kfree(hog->line_name); }