Re: [PATCH] serial: pic32_uart: Use devm for kasprintf and request_irq

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 04, 2024 at 01:53:53PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>
> 
> Use devm_kasprintf and devm_request_irq to simplify code.
> 
> Signed-off-by: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>
> ---
>  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




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux