From patchwork Fri Jun 9 09:59:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 103448 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp127962qgd; Fri, 9 Jun 2017 03:00:11 -0700 (PDT) X-Received: by 10.84.238.139 with SMTP id v11mr40366600plk.182.1497002411628; Fri, 09 Jun 2017 03:00:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497002411; cv=none; d=google.com; s=arc-20160816; b=vfkH/OJOfdhNXqczdK4c4rg9tynJK4gAtAWUySZppu0iStmmVfzjB6xPkTNJ2vj3H0 1qmjxqIh9aP4FOlqCKsy2dyGf2ybIAopdcFn583lrHO9nNdTGYiaxqeWE4kMirzo9JNo yarUag+3MIqtlgaB4ZLG/y6w6yEu0//Y9/UcxNvm/5DXfI/SEzvGq+1U5IXHZRVDoiVN m76/EwEaQRiHcLB+48RtKJWZGRz4CPuMm8ErhDqTRwS31u+s/cwG5sTvgcCy2HrZccC/ ZxSmXKv6eS58DQ4d7vGohVXI7eS3M/RCRwmwBsQ/E1wRaqxrEVfCzr8X9b9MJChTcrJ/ BtcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fifqN0Iohhhvk6Gh+Sz4R5n353bbvLkO+ID2QgxUP0Y=; b=Pr13s5g+/2J72A21pGLuJxLlT1TkaJVk5mx371KB6llzL2DX0VXXGO6bTyxIbWASPw 9x57oUx3BYW0OjTiuihsrB/rwERly7iL6O2VSpzg9mTfbT3b8SIOGw1HzfS2Sy+WfRRa z1wBS78tSgTnlXRNWYsoPbcbE6Sx0nYZgdVeGJKrYvFt86QZHQILBhSj+JvyYdcrbNp9 jzqIUJ5CbfKbITUKPxjzd8aIrT0sA+cGwv2Xm0zcKzUhKU2m5D9ww0ivLD9YN9AZVqht f/oYpEhme4IyYYCIa/woP67wwyhtn7v1oKI4O91pzmaXVcBVkzsP1zjswtNVBSkZQEfq Bngg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12si6673369pgs.309.2017.06.09.03.00.11; Fri, 09 Jun 2017 03:00:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751606AbdFIJ7p (ORCPT + 25 others); Fri, 9 Jun 2017 05:59:45 -0400 Received: from mail-wr0-f174.google.com ([209.85.128.174]:35723 "EHLO mail-wr0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751558AbdFIJ7m (ORCPT ); Fri, 9 Jun 2017 05:59:42 -0400 Received: by mail-wr0-f174.google.com with SMTP id q97so28298123wrb.2 for ; Fri, 09 Jun 2017 02:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fifqN0Iohhhvk6Gh+Sz4R5n353bbvLkO+ID2QgxUP0Y=; b=CWiWx0XtwKg93UEKiKf+1Cogpu3vgUwvC9gwAPXVQVFaX654X2LYuzZGEtr7NPMJPq tQlIHBLe8L94BdIZz48Qiqe6YZ2+aW/wLEEcqGiZSXtHfeVfSmzPm5XKKVnX2m4NGpSL /mJUUwLr3BIy5745PtaTtGer3ej245OK3YT4U= 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; bh=fifqN0Iohhhvk6Gh+Sz4R5n353bbvLkO+ID2QgxUP0Y=; b=I9YyclFUDqfyx+1p5hng9NkUBadxUTnmGymjAhgsdFYaIX0cIOMSPhYVurnIzufx3U 4dZmJHX9lCp/djdIA02IEP6ojBjq9Zx/2FD2hpEgJGtdiV4s0VWVXvs4M0w2tKhVxvw4 RvxOPFA2msXzWSpC7GXrEXb13/+/AWJ+BKAvcqhw/iRP68pQvUr7WjJ4qyqtZ0mgtX9B yGi29vvIG9/TKcMHr+gk0Cr3QZyCau2+Hpr2A0+03VYvkPw4Q8igPFq+PlhQZJ7VwhP5 MCl9u7pfPyIYm1Ba1/P46TWj10GeuTzFYiif4YiYdthb/t94TBb0Svd/zdI6Jv41ltmF +mqA== X-Gm-Message-State: AODbwcA5pKBBYgbyWlw93tw88pyCYnbbRgbGfw2cjG5likSpNASohwry w7f0x8p1rfn0yhTz X-Received: by 10.223.171.83 with SMTP id r19mr28284588wrc.7.1497002381123; Fri, 09 Jun 2017 02:59:41 -0700 (PDT) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id g46sm1031207wrg.69.2017.06.09.02.59.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Jun 2017 02:59:40 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: srinivas.kandagatla@linaro.org, linux-kernel@vger.kernel.org, Johan Hovold , "stable # 4 . 3" , Andrew Lunn , Mika Westerberg Subject: [PATCH 2/5] nvmem: core: fix leaks on registration errors Date: Fri, 9 Jun 2017 10:59:07 +0100 Message-Id: <20170609095910.4090-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170609095910.4090-1-srinivas.kandagatla@linaro.org> References: <20170609095910.4090-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johan Hovold Make sure to deregister and release the nvmem device and underlying memory on registration errors. Note that the private data must be freed using put_device() once the struct device has been initialised. Also note that there's a related reference leak in the deregistration function as reported by Mika Westerberg which is being fixed separately. Fixes: b6c217ab9be6 ("nvmem: Add backwards compatibility support for older EEPROM drivers.") Fixes: eace75cfdcf7 ("nvmem: Add a simple NVMEM framework for nvmem providers") Cc: stable # 4.3 Cc: Andrew Lunn Cc: Srinivas Kandagatla Cc: Mika Westerberg Signed-off-by: Johan Hovold Acked-by: Andrey Smirnov Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) -- 2.11.0 diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 8c830a80a648..6cf916d9db6d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -489,21 +489,24 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) rval = device_add(&nvmem->dev); if (rval) - goto out; + goto err_put_device; if (config->compat) { rval = nvmem_setup_compat(nvmem, config); if (rval) - goto out; + goto err_device_del; } if (config->cells) nvmem_add_cells(nvmem, config); return nvmem; -out: - ida_simple_remove(&nvmem_ida, nvmem->id); - kfree(nvmem); + +err_device_del: + device_del(&nvmem->dev); +err_put_device: + put_device(&nvmem->dev); + return ERR_PTR(rval); } EXPORT_SYMBOL_GPL(nvmem_register);