[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230321144813.00002c19@Huawei.com>
Date: Tue, 21 Mar 2023 14:48:13 +0000
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: Davidlohr Bueso <dave@...olabs.net>
CC: <linux-cxl@...r.kernel.org>, <peterz@...radead.org>,
<mingo@...hat.com>, <acme@...nel.org>, <mark.rutland@....com>,
<will@...nel.org>, <dan.j.williams@...el.com>,
<bwidawsk@...nel.org>, <ira.weiny@...el.com>,
<vishal.l.verma@...el.com>, <alison.schofield@...el.com>,
<linuxarm@...wei.com>, <linux-perf-users@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/4] cxl/pci: Find and register CXL PMU devices
On Mon, 6 Mar 2023 18:36:56 -0800
Davidlohr Bueso <dave@...olabs.net> wrote:
> On Fri, 03 Mar 2023, Jonathan Cameron wrote:
>
> >+int devm_cxl_cpmu_add(struct device *parent, struct cxl_cpmu_regs *regs, int index)
> >+{
> >+ struct cxl_cpmu *cpmu;
> >+ struct device *dev;
> >+ int rc;
> >+
> >+ cpmu = kzalloc(sizeof(*cpmu), GFP_KERNEL);
> >+ if (!cpmu)
> >+ return -ENOMEM;
> >+
> >+ cpmu->base = regs->cpmu;
> >+ dev = &cpmu->dev;
> >+ device_initialize(dev);
> >+ device_set_pm_not_required(dev);
> >+ dev->parent = parent;
> >+ dev->bus = &cxl_bus_type;
> >+ dev->type = &cxl_cpmu_type;
> >+ rc = ida_alloc(&cpmu_ida, GFP_KERNEL);
> >+ if (rc < 0)
> >+ goto err;
>
> Probably better to do the ida_alloc after the cpmu allocation above, before
> arming the dev.
Hi Davidlohr,
There was a bug hiding here I think as the device_put() could cause the ida
to be freed even though the ida_alloc() failed.
Good you pointed out this oddity.
Moving the ida_alloc earlier requires an explicit free of the cpmu
but that's easy enough to locally to that if (rc < 0)
Thanks,
Jonathan
Powered by blists - more mailing lists