Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1896132pxb; Thu, 16 Sep 2021 19:25:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+/j44Fk+i8gJQGw51/7aOfkbQC2WjLCPjIOmMbFAEzymwv4iCzZ/ec19NuDWXoB96FjyH X-Received: by 2002:aa7:d649:: with SMTP id v9mr10171461edr.38.1631845530342; Thu, 16 Sep 2021 19:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631845530; cv=none; d=google.com; s=arc-20160816; b=uXFrP08qgDwLNy0d9EH1eDfgYM6ts44RvSSLZun5VL6f9Jwhqo+npLOrxjWReUScVK wt8Rym4zauOMvnbxNC1dIE7FJlo90EMDXXLcFYRS3bvQH8wlook4NRN7FJvaC9+7fpFD 8nMwHZanwOPiy+HhFSQhrQqF6tf3Q91d++1yGGLWp1VioK8zHPg5SmMcR5xevCaTX8XA 7ZKhiHtiSL4V76xd3GhKMRlCzHVy/bCgenzO619gJbIqJkCqKvK14b8hushmUqWaf7WD IN++k93ESTZO4TzCHaXSCMmB/rW5Z1OG4w4w+ai8/gw2Rwv4fPjjMfieXq69wkZtNcoD JSlQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XUM3ia4ZShYupX5UDyiXTIQfntok9yHNCgClHZMFnDw=; b=0o3ButdZFMEUXpWK4fQzeQEF/h+5l6lMv104OIYKtolpo/V7dwSTXDFHMOAZdysGHd r98jL/YeDUsKCnVIeQAnoWxG2z945n7FoClfk+GQh9jnVVcLpmbUi+FGZchOhTe5KRnK pyE/ILq1W9wr5iVIdty4K2Iw7SgiXnJVnKlIhcY0m6oGNdbsC08hjJDSmETuskwEaJSq telj3rDnnM5Ss8d7IIctzXTuLfrn4wg2+efQGhRsvqIxg/0YfgTJJY3h7XT+zPk4w6/C FXfrsKLHL161uMZT4Hy1qTPIdEsw5JPjwQnfIklT/adx/NpKCkb+SVPpLTRW4P4V3wGG EdJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zsjj3grE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u19si5466721ejo.211.2021.09.16.19.25.04; Thu, 16 Sep 2021 19:25:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zsjj3grE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351105AbhIPROw (ORCPT + 99 others); Thu, 16 Sep 2021 13:14:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:36120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349946AbhIPRH7 (ORCPT ); Thu, 16 Sep 2021 13:07:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7048C60E54; Thu, 16 Sep 2021 16:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810203; bh=zbUiBWOE5ZgEzv+4F+zt20ryl/sw96hGxB3ORZm8ZJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zsjj3grEc6eiab5hx43aIpRzpKaVau89OCCARvMDgQEL08eTqdiLfleLymZAHcprn K5CfhOEy2qF1uHpR8uTz4Du5viinkEX53pvkZcEogcXxNM1XU1Cw+FIPjH99iqgSZj Q+iC9+lhwm9SRxIfE61XEAx7/MyLgcpdbY5+8WMY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH 5.14 053/432] nvmem: core: fix error handling while validating keepout regions Date: Thu, 16 Sep 2021 17:56:42 +0200 Message-Id: <20210916155812.597214198@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srinivas Kandagatla commit de0534df93474f268486c486ea7e01b44a478026 upstream. Current error path on failure of validating keepout regions is calling put_device, eventhough the device is not even registered at that point. Fix this by adding proper error handling of freeing ida and nvmem. Fixes: fd3bb8f54a88 ("nvmem: core: Add support for keepout regions") Cc: Signed-off-by: Srinivas Kandagatla Link: https://lore.kernel.org/r/20210806085947.22682-5-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/nvmem/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -824,8 +824,11 @@ struct nvmem_device *nvmem_register(cons if (nvmem->nkeepout) { rval = nvmem_validate_keepouts(nvmem); - if (rval) - goto err_put_device; + if (rval) { + ida_free(&nvmem_ida, nvmem->id); + kfree(nvmem); + return ERR_PTR(rval); + } } dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);