Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp489190ybd; Wed, 26 Jun 2019 01:28:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMmMWGnAX00t1uMfe/svUvzNpdJdX4zhgKR9+uSzTX/55Fb6ExLimMvzjoNdjnWDr9kGbY X-Received: by 2002:a17:902:b70f:: with SMTP id d15mr3833494pls.318.1561537735004; Wed, 26 Jun 2019 01:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561537734; cv=none; d=google.com; s=arc-20160816; b=lYuiHuwnXhqxCHEB3PVl/xtWX4qvMJaTNXW+3LeyYf6zGRmSCooShaOb6VVVO/n0oa nbwWA8BM0av50NRBEUiQDoryJYO6CAJqX296PNzCcIfGrcccbrMw2ztgVlB8DxIG8jyi PnQO62SSCMdf0HvuYH2zGLcmhS2bHjZr5kfzwfAQhVTGkTWPAThCGheDSuC29r9Bidzb ZDWSdQ+QDcLx6mEqPc1O2/X9zc3aQGb136OSJNl63SReVVLfMMzvzJW6UoHbxYSvh2Bo z951ljIvGpsolXlTETVVYLZQO6z83HzonPUZOPCDwIPBh1FLuxS+EMyEWHecudZqbwKz vGaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=pvggE4iPqwqSEZ2SZYODFNS7yEyGBKuNpIoSC3wKpGw=; b=DBWHgWEW5+S4cpMdkjSe9sJ28+UpHwpNHcL08qTxt8pBcRb0FMhJHttlugBp3w17FR lFEUsJ6Oyt0bFltXksfcRJvY1jEMh+cQuWeS4AOuWj28QEZKiVybNQJMHdci5usun2Se lTX2Sft0bG3dMnra2i6VCMMYY7Q7KBgVXEfJzNHZHmXN5yXp/Wn+kkcTqS8o/ENs5TeF CSyPS1yapygqXXDzP0WQ0cl2vZDozq15CJQfY0T6GkW8ph2cBySJuZ2NbmM5Iq0383UB gEMNEJtQztlmDZspvgbrSDeG+w0Sd7JGMCNE55ljq2iQqCbhMn05AzEigvXMO9uhK3ix qAyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y16si1678003pjj.80.2019.06.26.01.28.39; Wed, 26 Jun 2019 01:28:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726851AbfFZI1O (ORCPT + 99 others); Wed, 26 Jun 2019 04:27:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:60352 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726604AbfFZI1N (ORCPT ); Wed, 26 Jun 2019 04:27:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 04FA3AD7E; Wed, 26 Jun 2019 08:27:11 +0000 (UTC) Date: Wed, 26 Jun 2019 10:27:11 +0200 Message-ID: From: Takashi Iwai To: "Evan Green" Cc: , "Thomas Gleixner" , "Amadeusz S*awi*ski" , "Greg Kroah-Hartman" , "Jaroslav Kysela" , Subject: Re: [PATCH] ALSA: hda: Use correct start/count for sysfs init In-Reply-To: <20190625215418.17548-1-evgreen@chromium.org> References: <20190625215418.17548-1-evgreen@chromium.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Jun 2019 23:54:18 +0200, Evan Green wrote: > > The normal flow through the widget sysfs codepath is that > snd_hdac_refresh_widgets() is called once without the sysfs bool set > to set up codec->num_nodes and friends, then another time with the > bool set to actually allocate all the sysfs widgets. However, during > the first time allocation, hda_widget_sysfs_reinit() ignores the new > num_nodes passed in via parameter and just calls hda_widget_sysfs_init(), > using whatever was in codec->num_nodes before the update. This is not > correct in cases where num_nodes changes. Here's an example: > > Sometime earlier: > snd_hdac_refresh_widgets(hdac, false) > sets codec->num_nodes to 2, widgets is still not allocated > > Now: > snd_hdac_refresh_widgets(hdac, true) > hda_widget_sysfs_reinit(num_nodes=7) > hda_widget_sysfs_init() > widget_tree_create() > alloc(codec->num_nodes) // this is still 2 > codec->num_nodes = 7 > > Pass num_nodes and start_nid down into widget_tree_create() so that > the right number of nodes are allocated in all cases. > > Signed-off-by: Evan Green Thanks for the patch. That's indeed a problem, but I guess a simpler approach is just to return if sysfs didn't exist. If the sysfs entries aren't present at the second call with sysfs=true, it implies that the codec object will be exposed anyway later, and the sysfs will be created there. So, something like below would work instead? thanks, Takashi --- a/sound/hda/hdac_sysfs.c +++ b/sound/hda/hdac_sysfs.c @@ -428,7 +428,7 @@ int hda_widget_sysfs_reinit(struct hdac_device *codec, int i; if (!codec->widgets) - return hda_widget_sysfs_init(codec); + return 0; tree = kmemdup(codec->widgets, sizeof(*tree), GFP_KERNEL); if (!tree)