Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp481215pxt; Fri, 6 Aug 2021 06:42:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLo0wXLl5SacK6DJ+IPlIJ1F2a2iXhn7gAThk63IO8Pf4motSDrXZBlqYUePw/OVHE9Bh+ X-Received: by 2002:a17:906:388b:: with SMTP id q11mr9763522ejd.113.1628257372204; Fri, 06 Aug 2021 06:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628257372; cv=none; d=google.com; s=arc-20160816; b=zMJv9wKerN/KFlq/rGZyCUCJGN1V0/Cum1DmJztsNGVA0x/vTMB1C2UyDWhcd31bid JyaC6tuIZkQ0OzHGkOI+8BxLzVE196iCcck7ir6xGK0xzTbpDzrqHIaJ4VZY9NEDg1RC /W3uAcom1DY+UjmNhM4uHzo9dAsO+zFImIrN3OtvywDZsOPzaBiBFJ++o+5Tmow2LfU4 BMUSK0Ajy8hqoOzfK5NSyxhSfqQfshxj9JcYM4U2qQZ/bHVotTWH9chWtagwqyH57LbE udRrdcgOZbABGGrietYbVStvT9gXDSsNPgXnu1cbfZGUO6149rLs3Fc/3vM/w4sEBAJD l53g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7I/XnXmF8czTUjjocbGR8hsRDQOmub4O/8bSm3IY4iw=; b=NEqIpbVG255DCHrDoBk9g1MdOTCybHSdRVi0tVBz8+zSVsZindsDRBkb3y8HnNqcRR GYjbJCFEX0r6nEWGG7dZkMs1iChoD+egFFptl7wexN33ldyHZ5jLSa1noGIEFRyxU4M1 3Z+28FMwlaLl1G+Ss+2ydgIuj7JdJR37IDPHTnZLySkBXytdlTOfH7ZW45mUUxW7MVGm DN5Y0WkNtVYcrMFav8ZPu4LuLUKPFSWb+a59L5W8uuD+uMe7IGXQOolJ55p5nj6aHibV GHmmTzUrprjsrSW67NCqD38wqnS96q5mtWf+1CYIEgszk4l/eHXN2bYU9I59SDAWFzJR fTmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GDeLZ2K5; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f13si8340977eds.468.2021.08.06.06.42.28; Fri, 06 Aug 2021 06:42:52 -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=@linaro.org header.s=google header.b=GDeLZ2K5; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244133AbhHFJAU (ORCPT + 99 others); Fri, 6 Aug 2021 05:00:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244026AbhHFJAL (ORCPT ); Fri, 6 Aug 2021 05:00:11 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B2AC061798 for ; Fri, 6 Aug 2021 01:59:55 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id u15so5116412wmj.1 for ; Fri, 06 Aug 2021 01:59:55 -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 :mime-version:content-transfer-encoding; bh=7I/XnXmF8czTUjjocbGR8hsRDQOmub4O/8bSm3IY4iw=; b=GDeLZ2K5U8ga4Z+FnNl6UFp5fR8fpLUYILKNqsJVqN00NFcGG558ItPGEn1cWUaoSn iBdrzhQgfxK/nNukj/9QbbP9TTCHQveOMRK4/5v+fN4s6N5XFpabdNNQB1UOnl2rVk3c nvOG7deUfxTZjsXqhD2QJDMtJQw78q3B1C/IEYI0XyQ7RRr7Dgtc/BcjJsLzm4R0jjFP uq8ywxmaW6McZKv09W8/LZbH3nRgJGveEKHmJEpKuSsl/jDzABkwVExm+1PzH5QUpKoQ uPTWFMaOucz7nbFWEIzdyiQq2KQqr4aGJrGnkTkoTmFoD+RYj1yEqGK3P+YimWPDOHKU bbwg== 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=7I/XnXmF8czTUjjocbGR8hsRDQOmub4O/8bSm3IY4iw=; b=thI9Fqznm1lWL2FHFVdShFy7M6ELhEme6EI+PNKZ7mbHCecK3Osuxu5Odh2FcpcK5v owsfblBEGXS7CVhND24XrpIzU7wofPdPmfx3D9HaHiCQvk6iwaG9xhtNwGfhVKbM94is RXsyTWjjhWK/NkzUrLSL+5cjq/wnKMbhvDtJ+iOcBPSPxWptDFNxfudPJVVRmcSwalXf 2/YXgKPG6/QFf6BNaGBAU+jD7o8ZTKYcc7iLCKFKJlYt50qhc/ve79Tf3vj8J11d3r+J /W/hP028iAb7aTyJhbAMBtbzIbfesbp+UhdcxRRDgu5HJaPjoCkcsa7r+k9EWMQi2jsl +dAw== X-Gm-Message-State: AOAM532LhWaSwBHlgkuaNcg8CyZ04CjCfIoSQ+y3h36kmeZZ5jEPEG6o K2+VY7tLxwkNwiPFEKfALEIzjw== X-Received: by 2002:a05:600c:4f4d:: with SMTP id m13mr2188796wmq.32.1628240394472; Fri, 06 Aug 2021 01:59:54 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id x18sm8506144wrw.19.2021.08.06.01.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Aug 2021 01:59:54 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Srinivas Kandagatla , stable@vger.kernel.org Subject: [PATCH 4/4] nvmem: core: fix error handling while validating keepout regions Date: Fri, 6 Aug 2021 09:59:47 +0100 Message-Id: <20210806085947.22682-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210806085947.22682-1-srinivas.kandagatla@linaro.org> References: <20210806085947.22682-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/nvmem/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b3bc30a04ed7..3d87fadaa160 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -824,8 +824,11 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) 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); -- 2.21.0