Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753067AbdG1W6l (ORCPT ); Fri, 28 Jul 2017 18:58:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:40516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752691AbdG1W6j (ORCPT ); Fri, 28 Jul 2017 18:58:39 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68B2422CAA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=robh+dt@kernel.org MIME-Version: 1.0 In-Reply-To: <20170728082315.GL10026@atomide.com> References: <20170727094405.19778-1-tony@atomide.com> <20170728060127.GH10026@atomide.com> <20170728082315.GL10026@atomide.com> From: Rob Herring Date: Fri, 28 Jul 2017 17:58:17 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] device property: Fix usecount for of_graph_get_port_parent() To: Tony Lindgren Cc: Frank Rowand , Grant Likely , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , linux-omap , Mark Brown , Takashi Iwai , Kuninori Morimoto , Linux-ALSA Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3586 Lines: 96 On Fri, Jul 28, 2017 at 3:23 AM, Tony Lindgren wrote: > * Tony Lindgren [170727 23:02]: >> * Rob Herring [170727 15:19]: >> > On Thu, Jul 27, 2017 at 4:44 AM, Tony Lindgren wrote: >> > > --- a/drivers/of/property.c >> > > +++ b/drivers/of/property.c >> > > @@ -708,6 +708,15 @@ struct device_node *of_graph_get_port_parent(struct device_node *node) >> > > { >> > > unsigned int depth; >> > > >> > > + if (!node) >> > > + return NULL; >> > > + >> > > + /* >> > > + * Preserve usecount for passed in node as of_get_next_parent() >> > > + * will do of_node_put() on it. >> > > + */ >> > > + of_node_get(node); >> > >> > I think this messes up of_graph_get_remote_port_parent(). First it >> > calls of_graph_get_remote_endpoint which returns the endpoint node >> > with ref count incremented. Then you are incrementing it again here. >> >> Hmm OK looks like I missed that one. If we want to have >> of_graph_get_port_parent not trash the node passed to it, we should >> just change things there too: > > Found few more things to fix with git grep -C20 of_graph_get_port_parent, > below is v2. > > Can you all prese review again and do some testing. I also fixed up > audio-graph-scu-card but can't test that one. > > Regards, > > Tony > > 8< ------ > From tony Mon Sep 17 00:00:00 2001 > From: Tony Lindgren > Date: Thu, 27 Jul 2017 01:30:16 -0700 > Subject: [PATCHv2] device property: Fix usecount for > of_graph_get_port_parent() > > Fix inconsistent use of of_graph_get_port_parent() where > asoc_simple_card_parse_graph_dai() does of_node_get() before > calling it while other callers do not. We can fix this by > not trashing the node passed to of_graph_get_port_parent(). > > Let's also make sure the callers have correct refcounts and remove > related incorrect of_node_put() calls for of_for_each_phandle > as that's done by of_phandle_iterator_next() except when > we break out of the loop early. > > Let's fix both issues with a single patch to avoid kobject > refcounts getting messed up more if two patches are merged > separately. > > Otherwise strange issues can happen caused by memory corruption > caused by too many kobject_del() calls such as: > > BUG: sleeping function called from invalid context at > kernel/locking/mutex.c:747 > ... > (___might_sleep) > (__mutex_lock) > (mutex_lock_nested) > (kernfs_remove) > (kobject_del) > (kobject_put) > (of_get_next_parent) > (of_graph_get_port_parent) > (asoc_simple_card_parse_graph_dai [snd_soc_simple_card_utils]) > (asoc_graph_card_probe [snd_soc_audio_graph_card]) > > Fixes: 0ef472a973eb ("of_graph: add of_graph_get_port_parent()") > Fixes: 2692c1c63c29 ("ASoC: add audio-graph-card support") > Fixes: 1689333f8311 ("ASoC: simple-card-utils: add asoc_simple_card_parse_graph_dai()") > Cc: Mark Brown > Cc: Takashi Iwai > Cc: Kuninori Morimoto > Cc: alsa-devel@alsa-project.org > Signed-off-by: Tony Lindgren > --- > drivers/of/property.c | 17 +++++++++++++++-- > sound/soc/generic/audio-graph-card.c | 10 +++++----- > sound/soc/generic/audio-graph-scu-card.c | 15 +++++++++------ > sound/soc/generic/simple-card-utils.c | 8 +++----- > sound/soc/soc-core.c | 2 ++ > 5 files changed, 34 insertions(+), 18 deletions(-) LGTM. I'm assuming this will go thru ALSA tree. Reviewed-by: Rob Herring Rob