From: Greg KH <gregkh@linuxfoundation.org>
To: zhangjiao2 <zhangjiao2@cmss.chinamobile.com>
Cc: jirislaby@kernel.org, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org
Subject: Re: [PATCH] serial: pic32_uart: Use devm for kasprintf and request_irq
Date: Wed, 4 Sep 2024 09:59:33 +0200 [thread overview]
Message-ID: <2024090418-precook-fringe-c8b4@gregkh> (raw)
In-Reply-To: <20240904055353.102273-1-zhangjiao2@cmss.chinamobile.com>
On Wed, Sep 04, 2024 at 01:53:53PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
>
> Use devm_kasprintf and devm_request_irq to simplify code.
>
> Signed-off-by: zhang jiao <zhangjiao2@cmss.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
prev parent reply other threads:[~2024-09-04 7:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-04 5:53 [PATCH] serial: pic32_uart: Use devm for kasprintf and request_irq zhangjiao2
2024-09-04 7:59 ` Greg KH [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2024090418-precook-fringe-c8b4@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=zhangjiao2@cmss.chinamobile.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox