lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YFmRcPUxxFxkuMkr@vkoul-mobl.Dlink>
Date:   Tue, 23 Mar 2021 12:27:52 +0530
From:   Vinod Koul <vkoul@...nel.org>
To:     Bard Liao <yung-chuan.liao@...ux.intel.com>
Cc:     alsa-devel@...a-project.org, linux-kernel@...r.kernel.org,
        gregkh@...uxfoundation.org, srinivas.kandagatla@...aro.org,
        rander.wang@...ux.intel.com, hui.wang@...onical.com,
        pierre-louis.bossart@...ux.intel.com, sanyog.r.kale@...el.com,
        bard.liao@...el.com
Subject: Re: [PATCH] soundwire: add slave device to linked list after
 device_register()

On 23-03-21, 10:25, Bard Liao wrote:
> From: Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>
> 
> We currently add the slave device to a linked list before
> device_register(), and then remove it if device_register() fails.
> 
> It's not clear why this sequence was necessary, this patch moves the
> linked list management to after the device_register().

Maybe add a comment :-)

The reason here is that before calling device_register() we need to be
ready and completely initialized. device_register is absolutely the last
step in the flow, always.

The probe of the device can happen and before you get a chance to
add to list, many number of things can happen.. So adding after is not a
very good idea :)

HTH

> 
> Suggested-by: Keyon Jie <yang.jie@...ux.intel.com>
> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>
> Reviewed-by: Guennadi Liakhovetski <guennadi.liakhovetski@...ux.intel.com>
> Signed-off-by: Bard Liao <yung-chuan.liao@...ux.intel.com>
> ---
>  drivers/soundwire/slave.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c
> index 112b21967c7a..0c92db2e1ddc 100644
> --- a/drivers/soundwire/slave.c
> +++ b/drivers/soundwire/slave.c
> @@ -65,9 +65,6 @@ int sdw_slave_add(struct sdw_bus *bus,
>  	for (i = 0; i < SDW_MAX_PORTS; i++)
>  		init_completion(&slave->port_ready[i]);
>  
> -	mutex_lock(&bus->bus_lock);
> -	list_add_tail(&slave->node, &bus->slaves);
> -	mutex_unlock(&bus->bus_lock);
>  
>  	ret = device_register(&slave->dev);
>  	if (ret) {
> @@ -77,13 +74,15 @@ int sdw_slave_add(struct sdw_bus *bus,
>  		 * On err, don't free but drop ref as this will be freed
>  		 * when release method is invoked.
>  		 */
> -		mutex_lock(&bus->bus_lock);
> -		list_del(&slave->node);
> -		mutex_unlock(&bus->bus_lock);
>  		put_device(&slave->dev);
>  
>  		return ret;
>  	}
> +
> +	mutex_lock(&bus->bus_lock);
> +	list_add_tail(&slave->node, &bus->slaves);
> +	mutex_unlock(&bus->bus_lock);
> +
>  	sdw_slave_debugfs_init(slave);
>  
>  	return ret;
> -- 
> 2.17.1

-- 
~Vinod

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ