From patchwork Thu Sep 16 15:56:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 513016 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1414387jao; Thu, 16 Sep 2021 10:09:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7JOYts/m/I8c2Hdzfzh/K2nAyBSIzf5D2K0Q+KR/d1vAnH9uCFsFQk9I6rsaPVpXjrNLe X-Received: by 2002:a92:d352:: with SMTP id a18mr4603458ilh.160.1631812151038; Thu, 16 Sep 2021 10:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631812151; cv=none; d=google.com; s=arc-20160816; b=JBhd1Y4B+6CvPfjN7l7pwGLk5fx1g0KSpWm9CTCQJEtsuMBG0ieJpRKuV4oya6pu9m qNfpQhaIIFz0+ZZCLfACmxkS+FkoeFYMYT2/iG6zciYhNmb82Ou20mslVxuRubQDCY84 +L/FKMHiaRG9d7HT5cQLf0tD2n8myWy8cSgA/WrQvcKIgshtIiRKyOV0mHFmOo45mUTF 1jsWo3uQjaivSonrwH00Op104IMwLomEokVitgtdE/LAAn6dcT8dyV+rhp74LAGKViTZ UhQkTcHDvrxcnibWAkqb0cou/PfhJufaBDZnd2qr072j+3UtwRpS8zhcWPx5lqvSP6Is UKFg== 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=UiHJy3o3iVk4nY6uOAQ6+vFparAxkqwfox5gDHQ2pjNy0/10ck4DlnFAAy7uxnRQ07 2vdGRHqODyE0ANuK2uzup9J/S01m0tUf5PpNM1WTO6gJxpDEZpkYSEFp7S9IJaReh+uW SiT7mwwRha41/xbjsKM1iP2y/mmZ7vALA2UP5zvZ1WcNBKsaSMX+5H0ikzOq7LYqmbzU ODe3yCxrInE0YzV/q9JBkYBdLz+x7qRXzOZfvD6ubfwsMvKbRiRdOj5BkreMMrwuDSCW BickKbTlAwEmf8PzGRHOXHxZj0XQZOG3AU0zYr8joYaJGGXpKZHjyljDq+TEQ8xbEQIr mnRw== 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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 k3si3190856ilh.176.2021.09.16.10.09.10; Thu, 16 Sep 2021 10:09:11 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1345052AbhIPRK1 (ORCPT + 11 others); Thu, 16 Sep 2021 13:10:27 -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 Precedence: bulk List-ID: X-Mailing-List: stable@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);