From patchwork Tue Feb 18 09:42:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 207280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74E06C34033 for ; Tue, 18 Feb 2020 09:43:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C90F24125 for ; Tue, 18 Feb 2020 09:43:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="Wl2zXwiS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726281AbgBRJnZ (ORCPT ); Tue, 18 Feb 2020 04:43:25 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45557 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726199AbgBRJnA (ORCPT ); Tue, 18 Feb 2020 04:43:00 -0500 Received: by mail-wr1-f66.google.com with SMTP id g3so23016887wrs.12 for ; Tue, 18 Feb 2020 01:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZG2z268/d1ZPCLix4+2Jyx7EtKyi7olNnGdRbAveZ2A=; b=Wl2zXwiSHFbZl2UICxYrGvJRg6ZyvtsBfE6EzhmieYr3vsVZxG+oAFpwBc0io5tf0b W9mS7dXqwmia5CFkB66HGC61jim0o86iOvg7l7vW5fpUDUrCDqiVIUkZ0OSQ/ZltBLhK BFV2tdAvHYSLtBHyhQw++uXUqEw2hAEIHKStrkCDzd/Pn/quB3ilcHgq5BDLkx0dnHi+ KpUsanlT/LXV/mqoPLHPZsZLwGI299ahwEoZLaSwcAu+b7NI2h3wPeqhGNvSfs71inhe AE2IH6lvfBUSYpY31zOq9XE/EVEWhJu8u0uxF+feqE5wun3gN4jy+r57hgbrCrd0OHO8 JP4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZG2z268/d1ZPCLix4+2Jyx7EtKyi7olNnGdRbAveZ2A=; b=T51Ad22GUEahJ2irs/3wAmVtyeRq1CoSWvg7CjTTE1OE/iUSn5ohJSImY2BzZIBspH mew0x65MO14naagO1+OeyiuME9gjQ7x2Y6PzVRCoV+SYlBl6fFWru5YdEAtERXwqYa1e HAeAc4/wnsj+U+dxm7ggZ3qYcwnadqMhVFj1gH3t2vnASHJU90hgbaZAJkI9mroO9BLi bvX24Zo5lh87orTBSgBconu+ghI0CeK+KJ9b2ADLvGrK9KqKjfiV06EgB1DxuiYkTRmn lpZb0XIuVYO7V/Eybe8+YSb/5Klq+LecOMml88F8StighhNDOGsf3iMZKKfWDkFqVcm7 yKYg== X-Gm-Message-State: APjAAAW1o8+KMPCoU3hVrBIIx4GMSgm8dZBKimbnyX7D7VjG4IVpLU4D 2CpQk54LB3RQ+t6C0jSZAvDHMw== X-Google-Smtp-Source: APXvYqxbdKA1tOMV0VLCP3MMxkPL381W0uMOD0VBrLz3nDGgTSECjqZQnAItsFAYSzfbPyzcLkNJjQ== X-Received: by 2002:a05:6000:128a:: with SMTP id f10mr29135170wrx.116.1582018978979; Tue, 18 Feb 2020 01:42:58 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-188-94.w2-15.abo.wanadoo.fr. [2.15.37.94]) by smtp.gmail.com with ESMTPSA id s23sm5351095wra.15.2020.02.18.01.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 01:42:58 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , stable@vger.kernel.org Subject: [PATCH v2 2/7] nvmem: fix another memory leak in error path Date: Tue, 18 Feb 2020 10:42:29 +0100 Message-Id: <20200218094234.23896-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200218094234.23896-1-brgl@bgdev.pl> References: <20200218094234.23896-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski The nvmem struct is only freed on the first error check after its allocation and leaked after that. Fix it with a new label. Cc: Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b0be03d5f240..c9b3f4047154 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -343,10 +343,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) return ERR_PTR(-ENOMEM); rval = ida_simple_get(&nvmem_ida, 0, 0, GFP_KERNEL); - if (rval < 0) { - kfree(nvmem); - return ERR_PTR(rval); - } + if (rval < 0) + goto err_free_nvmem; if (config->wp_gpio) nvmem->wp_gpio = config->wp_gpio; else @@ -432,6 +430,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) put_device(&nvmem->dev); err_ida_remove: ida_simple_remove(&nvmem_ida, nvmem->id); +err_free_nvmem: + kfree(nvmem); return ERR_PTR(rval); } From patchwork Tue Feb 18 09:42:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 207281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65155C34035 for ; Tue, 18 Feb 2020 09:43:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D15924125 for ; Tue, 18 Feb 2020 09:43:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="TzKXLeGu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726327AbgBRJnT (ORCPT ); Tue, 18 Feb 2020 04:43:19 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36824 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726680AbgBRJnE (ORCPT ); Tue, 18 Feb 2020 04:43:04 -0500 Received: by mail-wr1-f67.google.com with SMTP id z3so23099608wru.3 for ; Tue, 18 Feb 2020 01:43:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4MJmrjeXUpfCiiOVSBqadBTktKzyE5G5Pyo6uC9T7RU=; b=TzKXLeGu7pUlbkJo/BBjLI/htilSMruo+BGbf2KDoYmGc2caA0R9BhtCS0AjsGBbL9 7HFh0IGlGw4FRWn6UL+PQHGTp/HPi+TlJALCD9LEa9HQYmKkDAtApUCk5GjvKVWqI1ku 5VNgNDl3FwpEhGce2/wrDilo5ZilFtQa5kwxtgAq8SsSbVY3wujJLi2C4WgS3Jkv1ogr P6Rc0lebaUROIFEjnkLeKSsBCJ1m091XNtAWGI5TCnr7XTWZNHaBY1C8OntkNFZBBHFs yI7n39OQHiK5r4oGJK486YNkIx80zhm/FkRQMT2nfW2AperE0TjHGA4hheWndPF8D4Tr D4gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4MJmrjeXUpfCiiOVSBqadBTktKzyE5G5Pyo6uC9T7RU=; b=PIecmhZhWUI72tpC8jtGpTIpk36pbiw6fS8g98OwZRi1fJCPvj0Biff5b5FNb4D0uh DvGSbjAKk3qik3pMHZAJSZMW60l8uvu50b0bFg+JrPfT73dzhr3MgD0mTyT1bTMnyyUF U6ZmnVcStSfnRoSJuIzLzHZdtBbmpVdSOO+qGXPxT8dwl8/MUCnPbKPp9CjQjPEpyeSb 8/qsTIgtFEui14ulbzIfYM8g7NdE1SmizdXbKGQMEH5HELtFz65Aa2v8sPg9T908vvFT WUydQIKBwv1IUlzRZl6XMEOyXZkS4DzIhg7EyYdsYLl2NkGMaa4GgkDJFE0lO620kXwL pzQQ== X-Gm-Message-State: APjAAAXj4y3efamZXNF24WlBZ0wml0E2uu7E/AAfciYLvtiMGCBG3r0B 9egqi9E3Nz0kV16lflSY3dg01Q== X-Google-Smtp-Source: APXvYqxJxka8qW+23GIFUP2hwrsAgK1suuyCEm3x4wMXUCnUkHAttDdt6PVQ/NuJFexYVJ8g1lMy9Q== X-Received: by 2002:a05:6000:367:: with SMTP id f7mr27386377wrf.174.1582018983376; Tue, 18 Feb 2020 01:43:03 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-188-94.w2-15.abo.wanadoo.fr. [2.15.37.94]) by smtp.gmail.com with ESMTPSA id s23sm5351095wra.15.2020.02.18.01.43.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 01:43:02 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 6/7] nvmem: remove a stray newline in nvmem_register() Date: Tue, 18 Feb 2020 10:42:33 +0100 Message-Id: <20200218094234.23896-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200218094234.23896-1-brgl@bgdev.pl> References: <20200218094234.23896-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Two newlines are unnecessary - remove one. Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index e47152e9db34..5e7d46eccaf6 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -354,7 +354,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (IS_ERR(nvmem->wp_gpio)) goto err_ida_remove; - kref_init(&nvmem->refcnt); INIT_LIST_HEAD(&nvmem->cells); From patchwork Tue Feb 18 09:42:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 207282 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40E03C34026 for ; Tue, 18 Feb 2020 09:43:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B62E24125 for ; Tue, 18 Feb 2020 09:43:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="GCaozWAz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbgBRJnG (ORCPT ); Tue, 18 Feb 2020 04:43:06 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39414 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbgBRJnG (ORCPT ); Tue, 18 Feb 2020 04:43:06 -0500 Received: by mail-wr1-f68.google.com with SMTP id y11so23035316wrt.6 for ; Tue, 18 Feb 2020 01:43:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1tGKCYnBEpjpoG5QSejrUPURgc2UVgvoiMB1koCeCZI=; b=GCaozWAzhz2rzE3xCPycDcZfcJEqLfqMgQo3eIz7yz4vHoD1VyK54/EwdkV5KLeIEs kbsuHvMVu4ZPMyBOJfO+Gc3z2MPajyZGfG7z0g4X5mpq+bevno2+vcVtdt1sAU46rzQG vxmGaHfYDiWmrah4zwJxta/GwJpkfZsn19u+lPFY0VlbXwTxu3IWmQkEwYAnhkVmorel pIyMeeAIHglpnFeJKWHwDXbWA3tuC07pSrYe8S9AzG23GnAzbqIOV2xnptCCJCKACjqu 3RLJUvOs+Xqy3WpIfGaPRCUe+njTB2kYKCavPhHCML0TSt2PnFcFSjuUG5csSmQ0z6iy MkIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1tGKCYnBEpjpoG5QSejrUPURgc2UVgvoiMB1koCeCZI=; b=VMK2IwG5aId1wyEiT3MiLd7yMIUnUj5D9Q75PUyeVnKpD9s6++RiEiplgY843p7kJu 0GMkeTc013rdhR16fDNIdiaCw3LJFNRuAkDfJ4vQNKBE6bHvDfds98gA/dCt0ac/Nq+X nIFJDo9a1etzM2kQbiHqigzC292EyAOG2XZeosPVc4mS6GxcpWB5m/oTX774y/qpG5S/ 4M4ojUCl8wLlzgCcPNHBswqQfPhMZoyYiYBIJ3cbZfRhM3pkr7PYXZLyYFn5xAVBlgue jbwRhi1UDSMVWaFbNiWPAjs1iKxokQ2dYqHIKSlY1mIQMjOEJDaTtzesyB0JTfLiw2ZV Auyw== X-Gm-Message-State: APjAAAULCo3THnfPSuwSNP4TEveCCUAqEJM4x5B6Z+LvZPHACrUm19e+ uPpelVI5t/49lYAE2gP+PsIPlQ== X-Google-Smtp-Source: APXvYqyaik2K3jmCriYAi/Btuue1NpMxh6Kl4mMKAIzp4/pL1q8QhpdD78hGoBibP9oQDkjFFVN9Pw== X-Received: by 2002:a5d:4746:: with SMTP id o6mr1437713wrs.70.1582018984313; Tue, 18 Feb 2020 01:43:04 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-188-94.w2-15.abo.wanadoo.fr. [2.15.37.94]) by smtp.gmail.com with ESMTPSA id s23sm5351095wra.15.2020.02.18.01.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 01:43:03 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 7/7] nvmem: add a newline for readability Date: Tue, 18 Feb 2020 10:42:34 +0100 Message-Id: <20200218094234.23896-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200218094234.23896-1-brgl@bgdev.pl> References: <20200218094234.23896-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Visibly separate the GPIO request from the previous operation in the code with a newline. Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 5e7d46eccaf6..ec955db4673c 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -346,6 +346,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) rval = ida_simple_get(&nvmem_ida, 0, 0, GFP_KERNEL); if (rval < 0) goto err_free_nvmem; + if (config->wp_gpio) nvmem->wp_gpio = gpiod_ref(config->wp_gpio); else