From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.bootlin.com ([62.4.15.54]:44645 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728063AbeIGTTt (ORCPT ); Fri, 7 Sep 2018 15:19:49 -0400 Date: Fri, 7 Sep 2018 16:38:24 +0200 From: Miquel Raynal To: Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut Cc: linux-mtd@lists.infradead.org, stable@vger.kernel.org, =?UTF-8?B?UmFm?= =?UTF-8?B?YcWCIE1pxYJlY2tp?= Subject: Re: [PATCH] mtd: partitions: fix of_node_get/put balance in parser Message-ID: <20180907163824.6cec1a43@xps13> In-Reply-To: <20180907143554.13496-1-miquel.raynal@bootlin.com> References: <20180907143554.13496-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: stable-owner@vger.kernel.org List-ID: Hello, I forgot to add Rafal which I know worked a lot on the parsers. Miquel Raynal wrote on Fri, 7 Sep 2018 16:35:54 +0200: > While at first mtd_part_of_parse() would just call > of_get_chil_by_name(), it has been edited to first try to get the OF > node thanks to mtd_get_of_node() and fallback on > of_get_child_by_name(). > > A of_node_put() was a bit below in the code, to balance the > of_get_child_by_name(). However, despite its name, mtd_get_of_node() > does not take a reference on the OF node. It is a simple helper hiding > some pointer logic to retrieve the OF node related to an MTD > device. People often used it this way: > > of_node_put(mtd_get_of_node()). > > The direct effect of such unbalanced reference counting is visible by > rmmod'ing any module that would have added MTD partitions: > > OF: ERROR: Bad of_node_put() on > > As it seems normal to get a reference on the OF node during the > of_property_for_each_string() that follows, add a call to > of_node_get() when relevant. > > Fixes: 76a832254ab0 ("mtd: partitions: use DT info for parsing partitions with "compatible" prop") > Cc: stable@vger.kernel.org > Signed-off-by: Miquel Raynal > --- > drivers/mtd/mtdpart.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c > index 52e2cb35fc79..99c460facd5e 100644 > --- a/drivers/mtd/mtdpart.c > +++ b/drivers/mtd/mtdpart.c > @@ -873,8 +873,11 @@ static int mtd_part_of_parse(struct mtd_info *master, > int ret, err = 0; > > np = mtd_get_of_node(master); > - if (!mtd_is_partition(master)) > + if (mtd_is_partition(master)) > + of_node_get(np); > + else > np = of_get_child_by_name(np, "partitions"); > + > of_property_for_each_string(np, "compatible", prop, compat) { > parser = mtd_part_get_compatible_parser(compat); > if (!parser)