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] [day] [month] [year] [list]
Message-ID: <2024090418-precook-fringe-c8b4@gregkh>
Date: Wed, 4 Sep 2024 09:59:33 +0200
From: Greg KH <gregkh@...uxfoundation.org>
To: zhangjiao2 <zhangjiao2@...s.chinamobile.com>
Cc: jirislaby@...nel.org, linux-kernel@...r.kernel.org,
	linux-serial@...r.kernel.org
Subject: Re: [PATCH] serial: pic32_uart: Use devm for kasprintf and
 request_irq

On Wed, Sep 04, 2024 at 01:53:53PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@...s.chinamobile.com>
> 
> Use devm_kasprintf and devm_request_irq to simplify code.
> 
> Signed-off-by: zhang jiao <zhangjiao2@...s.chinamobile.com>
> ---
>  drivers/tty/serial/pic32_uart.c | 31 +++++++++++--------------------
>  1 file changed, 11 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uart.c
> index 261c8115a700..0119a4d81521 100644
> --- a/drivers/tty/serial/pic32_uart.c
> +++ b/drivers/tty/serial/pic32_uart.c
> @@ -484,7 +484,7 @@ static int pic32_uart_startup(struct uart_port *port)
>  	 */
>  	sport->enable_tx_irq = false;
>  
> -	sport->irq_fault_name = kasprintf(GFP_KERNEL, "%s%d-fault",
> +	sport->irq_fault_name = devm_kasprintf(port->dev, GFP_KERNEL, "%s%d-fault",
>  					  pic32_uart_type(port),
>  					  sport->idx);
>  	if (!sport->irq_fault_name) {
> @@ -493,49 +493,49 @@ static int pic32_uart_startup(struct uart_port *port)
>  		goto out_disable_clk;
>  	}
>  	irq_set_status_flags(sport->irq_fault, IRQ_NOAUTOEN);
> -	ret = request_irq(sport->irq_fault, pic32_uart_fault_interrupt,
> +	ret = devm_request_irq(port->dev, sport->irq_fault, pic32_uart_fault_interrupt,
>  			  IRQF_NO_THREAD, sport->irq_fault_name, port);
>  	if (ret) {
>  		dev_err(port->dev, "%s: request irq(%d) err! ret:%d name:%s\n",
>  			__func__, sport->irq_fault, ret,
>  			pic32_uart_type(port));
> -		goto out_f;
> +		goto out_disable_clk;
>  	}
>  
> -	sport->irq_rx_name = kasprintf(GFP_KERNEL, "%s%d-rx",
> +	sport->irq_rx_name = devm_kasprintf(port->dev, GFP_KERNEL, "%s%d-rx",
>  				       pic32_uart_type(port),
>  				       sport->idx);
>  	if (!sport->irq_rx_name) {
>  		dev_err(port->dev, "%s: kasprintf err!", __func__);
>  		ret = -ENOMEM;
> -		goto out_f;
> +		goto out_disable_clk;
>  	}
>  	irq_set_status_flags(sport->irq_rx, IRQ_NOAUTOEN);
> -	ret = request_irq(sport->irq_rx, pic32_uart_rx_interrupt,
> +	ret = devm_request_irq(port->dev, sport->irq_rx, pic32_uart_rx_interrupt,
>  			  IRQF_NO_THREAD, sport->irq_rx_name, port);
>  	if (ret) {
>  		dev_err(port->dev, "%s: request irq(%d) err! ret:%d name:%s\n",
>  			__func__, sport->irq_rx, ret,
>  			pic32_uart_type(port));
> -		goto out_r;
> +		goto out_disable_clk;
>  	}
>  
> -	sport->irq_tx_name = kasprintf(GFP_KERNEL, "%s%d-tx",
> +	sport->irq_tx_name = devm_kasprintf(port->dev, GFP_KERNEL, "%s%d-tx",
>  				       pic32_uart_type(port),
>  				       sport->idx);
>  	if (!sport->irq_tx_name) {
>  		dev_err(port->dev, "%s: kasprintf err!", __func__);
>  		ret = -ENOMEM;
> -		goto out_r;
> +		goto out_disable_clk;
>  	}
>  	irq_set_status_flags(sport->irq_tx, IRQ_NOAUTOEN);
> -	ret = request_irq(sport->irq_tx, pic32_uart_tx_interrupt,
> +	ret = devm_request_irq(port->dev, sport->irq_tx, pic32_uart_tx_interrupt,
>  			  IRQF_NO_THREAD, sport->irq_tx_name, port);
>  	if (ret) {
>  		dev_err(port->dev, "%s: request irq(%d) err! ret:%d name:%s\n",
>  			__func__, sport->irq_tx, ret,
>  			pic32_uart_type(port));
> -		goto out_t;
> +		goto out_disable_clk;
>  	}
>  
>  	local_irq_save(flags);
> @@ -557,15 +557,6 @@ static int pic32_uart_startup(struct uart_port *port)
>  
>  	return 0;
>  
> -out_t:
> -	free_irq(sport->irq_tx, port);
> -	kfree(sport->irq_tx_name);
> -out_r:
> -	free_irq(sport->irq_rx, port);
> -	kfree(sport->irq_rx_name);
> -out_f:
> -	free_irq(sport->irq_fault, port);
> -	kfree(sport->irq_fault_name);
>  out_disable_clk:
>  	clk_disable_unprepare(sport->clk);
>  out_done:
> -- 
> 2.33.0
> 
> 
> 
> 

You obviously did not test this patch, why not?

If you really want to do conversions to use devm, PLEASE PLEASE PLEASE
understand the api and how it works.  As it is, this patch is totally
broken and will cause crashes if applied.

Please only submit changes that you have actually tested, otherwise
things like this will happen.

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ