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]
Date:   Wed, 7 Dec 2022 22:28:00 +0200
From:   Andy Shevchenko <andriy.shevchenko@...el.com>
To:     Tony Lindgren <tony@...mide.com>
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
        Jiri Slaby <jirislaby@...nel.org>,
        Johan Hovold <johan@...nel.org>,
        Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
        Vignesh Raghavendra <vigneshr@...com>,
        linux-serial@...r.kernel.org, linux-omap@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH v4 1/1] serial: core: Start managing serial
 controllers to enable runtime PM

On Wed, Dec 07, 2022 at 10:22:11PM +0200, Andy Shevchenko wrote:
> On Wed, Dec 07, 2022 at 02:43:05PM +0200, Tony Lindgren wrote:

...

> > +int serial_core_register_port(struct uart_driver *drv, struct uart_port *port)
> > +{
> 
> > +	bool allocated = false;
> 
> Not sure why this is needed.

Okay, I got it.
Still, see below.

> > +	struct device *ctrl_dev;
> > +	int ret;
> > +
> > +	ret = serial_core_add_one_port(drv, port);
> > +	if (ret)
> > +		return ret;
> > +
> > +	mutex_lock(&port_mutex);
> > +
> > +	/* Inititalize a serial core controller device if needed */
> > +	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
> > +	if (!ctrl_dev) {
> > +		ctrl_dev = serial_core_ctrl_device_add(port);
> > +		if (!ctrl_dev)
> > +			goto err_remove_port;
> > +		allocated = true;
> > +	}
> 
> Wouldn't be slightly better
> 
> 	ctrl_dev = serial_core_ctrl_find(drv, port->dev, port->ctrl_id);
> 	if (!ctrl_dev)
> 		ctrl_dev = serial_core_ctrl_device_add(port);
> 	if (!ctrl_dev)
> 		goto err_remove_port;
> 
> ?
> 
> > +	/* Initialize a serial core port device */
> > +	ret = serial_core_port_device_add(ctrl_dev, port);
> > +	if (ret)
> > +		goto err_del_ctrl_dev;
> > +
> > +	mutex_unlock(&port_mutex);
> > +
> > +	return 0;
> > +
> > +err_del_ctrl_dev:
> > +	if (allocated)

We can avoid this check by caching the platform device.

	struct platform_device *ctrl_pdev = NULL;

	if (...) {
		ctrl_pdev = to_platform_device(ctrl_dev);
	}

	platform_device_del(ctrl_pdev);

> > +		platform_device_del(to_platform_device(ctrl_dev));
> 
> Shouldn't you call platform_device_unregister()?
> 
> > +err_remove_port:
> > +	mutex_unlock(&port_mutex);
> > +
> > +	return serial_core_remove_one_port(drv, port);
> > +}

-- 
With Best Regards,
Andy Shevchenko


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ