[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2d5c9d87-abbc-4118-9031-f2c7b5c96085@lunn.ch>
Date: Thu, 13 Feb 2025 14:55:23 +0100
From: Andrew Lunn <andrew@...n.ch>
To: Chenyuan Yang <chenyuan0y@...il.com>
Cc: Andrew Jeffery <andrew@...econstruct.com.au>, joel@....id.au,
richardcochran@...il.com, linux-arm-kernel@...ts.infradead.org,
linux-aspeed@...ts.ozlabs.org, linux-kernel@...r.kernel.org,
netdev@...r.kernel.org
Subject: Re: [PATCH] soc: aspeed: Add NULL pointer check in
aspeed_lpc_enable_snoop()
On Wed, Feb 12, 2025 at 07:50:49PM -0600, Chenyuan Yang wrote:
> Hi Andrew,
>
> I've drafted the following patch to address the resource cleanup issue:
Please just follow the normal procedure of submitting a patch.
Andrew
>
> ```
> drivers/soc/aspeed/aspeed-lpc-snoop.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c
> b/drivers/soc/aspeed/aspeed-lpc-snoop.c
> index 9ab5ba9cf1d6..4988144aba88 100644
> --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c
> +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c
> @@ -200,11 +200,15 @@ static int aspeed_lpc_enable_snoop(struct
> aspeed_lpc_snoop *lpc_snoop,
> lpc_snoop->chan[channel].miscdev.minor = MISC_DYNAMIC_MINOR;
> lpc_snoop->chan[channel].miscdev.name =
> devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, channel);
> + if (!lpc_snoop->chan[channel].miscdev.name) {
> + rc = -ENOMEM;
> + goto free_fifo;
> + }
You were asked to first add cleanup, then fix this possible NULL
pointer dereference.
> I have a couple of questions regarding the cleanup order:
>
> 1. Do we need to call misc_deregister() in this case, considering that
> the registration happens before return -EINVAL?
> 2. If misc_deregister() is required, is there a specific order we
> should follow when calling misc_deregister() and
> kfree(lpc_snoop->chan[channel].miscdev.name);?
As a general rule, cleanup is the opposite order to setup.
Also, you want to do some research about that devm_ means.
Andrew
Powered by blists - more mailing lists