Re: [PATCH v2] clk: hisilicon: Improve deallocation in error path

From: Brian Masney

Date: Thu Mar 05 2026 - 06:12:39 EST


On Thu, Mar 05, 2026 at 09:02:11AM +0000, J. Neuschäfer wrote:
> On Wed, Mar 04, 2026 at 10:00:15AM -0500, Brian Masney wrote:
> > On Tue, Mar 03, 2026 at 04:25:18PM +0100, J. Neuschäfer via B4 Relay wrote:
> > > From: "J. Neuschäfer" <j.ne@xxxxxxxxxx>
> > >
> > > Unmap 'base' if an error occurs after it has been mapped.
> > >
> > > Reported-by: Tao Lan <taolan@xxxxxxxxxx>
> > > Closes: https://lore.kernel.org/lkml/ZNlSH+eWV8Sk3FYn@probook/
> > > Signed-off-by: J. Neuschäfer <j.ne@xxxxxxxxxx>
> >
> > My understanding is that you need to use your full first name in the
> > Signed-off-by.
>
> I have been contributing to the Linux kernel and other projects using my
> abbreviated first name for over a year. It has been mostly well received.

Sorry I should have checked.

> > > Changes in v2:
> > > - Rebase on v7.0-rc2
> > > - Update my email address
> > > - Reword the commit message somewhat
> > > - Link to v1: https://lore.kernel.org/r/20240708-hisi-error-v1-1-727bc7399b63@xxxxxxx
> > > ---
> > > drivers/clk/hisilicon/clk.c | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c
> > > index fae65127cd4aa8..08050ff1c8cf9a 100644
> > > --- a/drivers/clk/hisilicon/clk.c
> > > +++ b/drivers/clk/hisilicon/clk.c
> > > @@ -70,7 +70,7 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
> > >
> > > clk_data = kzalloc_obj(*clk_data);
> > > if (!clk_data)
> > > - goto err;
> > > + goto err_base;
> > >
> > > clk_data->base = base;
> > > clk_table = kzalloc_objs(*clk_table, nr_clks);
> > > @@ -83,6 +83,8 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
> > > return clk_data;
> > > err_data:
> > > kfree(clk_data);
> > > +err_base:
> > > + iounmap(base);
> >
> > Use devm_of_iomap() and it will be automatically cleaned up for you.
>
> This would require a larger restructuring of the HiSilicon clock drivers
> to pass a struct device * to hisi_clk_init. I'd rather avoid that
> because I can't currently test these drivers and because the benefit is
> questionable. However, I still had the upstreaming of this patch in my
> backlog, and I think it's simple enough to review as is.

OK, fair enough.

Reviewed-by: Brian Masney <bmasney@xxxxxxxxxx>