From patchwork Mon Mar 1 16:06:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 388727 Delivered-To: patch@linaro.org Received: by 2002:a02:290e:0:0:0:0:0 with SMTP id p14csp3644204jap; Mon, 1 Mar 2021 11:49:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzoHejJJ4HEgQLubt39JBjJHKfdw3O2US2sUINNl/ma5yavHD17Bp+6SkkmDvzFFHmQ+Jy3 X-Received: by 2002:a17:907:3d01:: with SMTP id gm1mr10889352ejc.214.1614628141907; Mon, 01 Mar 2021 11:49:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614628141; cv=none; d=google.com; s=arc-20160816; b=D0PdRfR0ibNXhpIl0PPzf44E5kJLZwJpH7NsEf4J2fcHIs/DUg3z+fQvUmw1NVTke3 Y+qSo9EOoJWjQKKraA2MTSpyJEkZkaV49BlWdlKugDmUBRtbFZEvGaEJOw4gUIVJSvKv 3iQGPaECHvQpyQiZ3hvpI1wBHdguNVet2YjxKaHk6LoRYJVI/vx59z+kilz8nhb+76e1 pTduNqM9KyM1qQIbdMENNLWgv71bvRDrMQzuzb4OTm5UdO2EvKVV6Vi8Ei6h1ZKbRMvI axrjzDW0mmrf6KpG168ebAXHmYszYVuUWXP0j4GHnLUXyZzYy1M6tN1j3jLIcw38SCcE xBhw== 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=2qVV/tF98xnG3QToxmWLBn5dtZ8RgeYp5KaXSmM4u+4=; b=gRzjvUc1ZCOPSoDHSxpXoltbN0xgj+l+QT37Jeo9CVC7V3oJYXOz8w44ViQlvbGVUa RTrk8IKNoqEXVatSSwOjNJUjdVgC3hEmtMpzOVaN2wh7Gk5v1brCBmVi3YT+F9lGpR20 0kNnUDVFFDj5wHYQVi6PF25MCtVxMY8Kh97ID1metxpshhOH+dcdM5JS7QU0eMKn070Z SDCGZjdriBoU4nQCr9GLkHrCeauJa8E+fJkGK+9AK6RtIXaLQOGeYFefA4QxPk1XeB6o AZUeL0tzvbf+3whBohNEmEgkq/mfgaLgDcJivUQi5HdAYikxto1+Pz7l2G09IkgXOI+C PVaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dynvvGPU; 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 j23si11491419eje.581.2021.03.01.11.49.01; Mon, 01 Mar 2021 11:49:01 -0800 (PST) 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=dynvvGPU; 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 S242335AbhCATs1 (ORCPT + 13 others); Mon, 1 Mar 2021 14:48:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:53030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241737AbhCATix (ORCPT ); Mon, 1 Mar 2021 14:38:53 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D771165352; Mon, 1 Mar 2021 17:45:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614620710; bh=gbpTDs9dPGrfRvSfxK5g4DorA6fv3N4bKFCME0f10GQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dynvvGPUoAd1ZPr0LCUBrcbtQ3PLKNdSBJMeQ4Any7hp1PTJHOMd/qWndnorDxD5K i8vLqkXoctY78svMpqDgdt49l/gPAgiq1q7EPw2aw9Ih1rvUhDcYU9yZ7T6SM53h4S yTs3B3nDergfrcgZQ3PnsgZe2A+T8UmVUPt0p2Bo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Manivannan Sadhasivam , Linus Walleij , Miquel Raynal , Sasha Levin Subject: [PATCH 5.11 251/775] mtd: parsers: afs: Fix freeing the part name memory in failure Date: Mon, 1 Mar 2021 17:06:59 +0100 Message-Id: <20210301161214.034559277@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161201.679371205@linuxfoundation.org> References: <20210301161201.679371205@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Manivannan Sadhasivam [ Upstream commit 7b844cf445f0a7daa68be0ce71eb2c88d68b0c5d ] In the case of failure while parsing the partitions, the iterator should be pre decremented by one before starting to free the memory allocated by kstrdup(). Because in the failure case, kstrdup() will not succeed and thus no memory will be allocated for the current iteration. Fixes: 1fca1f6abb38 ("mtd: afs: simplify partition parsing") Signed-off-by: Manivannan Sadhasivam Reviewed-by: Linus Walleij Cc: Linus Walleij Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20210104041137.113075-5-manivannan.sadhasivam@linaro.org Signed-off-by: Sasha Levin --- drivers/mtd/parsers/afs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) -- 2.27.0 diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c index 980e332bdac48..26116694c821b 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -370,10 +370,8 @@ static int parse_afs_partitions(struct mtd_info *mtd, return i; out_free_parts: - while (i >= 0) { + while (--i >= 0) kfree(parts[i].name); - i--; - } kfree(parts); *pparts = NULL; return ret;