diff mbox series

[27/32] ocrdma: Convert ocrdma_dev_id to IDA

Message ID 20190221002107.22625-28-willy@infradead.org (mailing list archive)
State Superseded
Delegated to: Jason Gunthorpe
Headers show
Series Convert the Infiniband subsystem to XArray | expand

Commit Message

Matthew Wilcox Feb. 21, 2019, 12:21 a.m. UTC
This driver doesn't look up the pointer that it stores, so this can
just be an IDA and save some memory.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/infiniband/hw/ocrdma/ocrdma_main.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Comments

Jason Gunthorpe Feb. 21, 2019, 11:25 p.m. UTC | #1
On Wed, Feb 20, 2019 at 04:21:02PM -0800, Matthew Wilcox wrote:
> This driver doesn't look up the pointer that it stores, so this can
> just be an IDA and save some memory.
> 
> Signed-off-by: Matthew Wilcox <willy@infradead.org>
> ---
>  drivers/infiniband/hw/ocrdma/ocrdma_main.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> index 1f393842453a..b014eeffbcce 100644
> --- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> @@ -62,7 +62,7 @@ MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
>  MODULE_AUTHOR("Emulex Corporation");
>  MODULE_LICENSE("Dual BSD/GPL");
>  
> -static DEFINE_IDR(ocrdma_dev_id);
> +static DEFINE_IDA(ocrdma_dev_id);
>  
>  void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
>  {
> @@ -302,12 +302,12 @@ static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
>  	}
>  	dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
>  	if (!dev->mbx_cmd)
> -		goto idr_err;
> +		goto ida_err;
>  
>  	memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
> -	dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL);
> +	dev->id = ida_alloc(&ocrdma_dev_id, GFP_KERNEL);

WTF.. There are only three places where this id is used:
 - A whole bunch of pr_* calls which *really* should be dev_* calls
   with no ID (grrrr)
 - It is passed to userspace in the ucontext udata, and userpace
   ignores it (double grrrrr)
 - It is used to form a name for request_irq (use the pci BDF)

We should delete this thing :(

Jason
Devesh Sharma Feb. 27, 2019, 8:44 a.m. UTC | #2
On Fri, Feb 22, 2019 at 4:55 AM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Wed, Feb 20, 2019 at 04:21:02PM -0800, Matthew Wilcox wrote:
> > This driver doesn't look up the pointer that it stores, so this can
> > just be an IDA and save some memory.
> >
> > Signed-off-by: Matthew Wilcox <willy@infradead.org>
> > ---
> >  drivers/infiniband/hw/ocrdma/ocrdma_main.c | 16 +++++++---------
> >  1 file changed, 7 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > index 1f393842453a..b014eeffbcce 100644
> > --- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > @@ -62,7 +62,7 @@ MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
> >  MODULE_AUTHOR("Emulex Corporation");
> >  MODULE_LICENSE("Dual BSD/GPL");
> >
> > -static DEFINE_IDR(ocrdma_dev_id);
> > +static DEFINE_IDA(ocrdma_dev_id);
> >
> >  void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
> >  {
> > @@ -302,12 +302,12 @@ static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
> >       }
> >       dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
> >       if (!dev->mbx_cmd)
> > -             goto idr_err;
> > +             goto ida_err;
> >
> >       memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
> > -     dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL);
> > +     dev->id = ida_alloc(&ocrdma_dev_id, GFP_KERNEL);
>
> WTF.. There are only three places where this id is used:
>  - A whole bunch of pr_* calls which *really* should be dev_* calls
>    with no ID (grrrr)
>  - It is passed to userspace in the ucontext udata, and userpace
>    ignores it (double grrrrr)
>  - It is used to form a name for request_irq (use the pci BDF)
>
> We should delete this thing :(
>

Will send a patch to remove this.
> Jason
Jason Gunthorpe March 29, 2019, 5:56 p.m. UTC | #3
On Wed, Feb 27, 2019 at 4:45 AM Devesh Sharma
<devesh.sharma@broadcom.com> wrote:
>
> On Fri, Feb 22, 2019 at 4:55 AM Jason Gunthorpe <jgg@ziepe.ca> wrote:
> >
> > On Wed, Feb 20, 2019 at 04:21:02PM -0800, Matthew Wilcox wrote:
> > > This driver doesn't look up the pointer that it stores, so this can
> > > just be an IDA and save some memory.
> > >
> > > Signed-off-by: Matthew Wilcox <willy@infradead.org>
> > > ---
> > >  drivers/infiniband/hw/ocrdma/ocrdma_main.c | 16 +++++++---------
> > >  1 file changed, 7 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > > index 1f393842453a..b014eeffbcce 100644
> > > --- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > > +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > > @@ -62,7 +62,7 @@ MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
> > >  MODULE_AUTHOR("Emulex Corporation");
> > >  MODULE_LICENSE("Dual BSD/GPL");
> > >
> > > -static DEFINE_IDR(ocrdma_dev_id);
> > > +static DEFINE_IDA(ocrdma_dev_id);
> > >
> > >  void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
> > >  {
> > > @@ -302,12 +302,12 @@ static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
> > >       }
> > >       dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
> > >       if (!dev->mbx_cmd)
> > > -             goto idr_err;
> > > +             goto ida_err;
> > >
> > >       memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
> > > -     dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL);
> > > +     dev->id = ida_alloc(&ocrdma_dev_id, GFP_KERNEL);
> >
> > WTF.. There are only three places where this id is used:
> >  - A whole bunch of pr_* calls which *really* should be dev_* calls
> >    with no ID (grrrr)
> >  - It is passed to userspace in the ucontext udata, and userpace
> >    ignores it (double grrrrr)
> >  - It is used to form a name for request_irq (use the pci BDF)
> >
> > We should delete this thing :(
> >
>
> Will send a patch to remove this.

Devesh, will  a patch be coming?

Thanks,
Jason
Devesh Sharma April 1, 2019, 6:11 p.m. UTC | #4
On Fri, Mar 29, 2019 at 11:27 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Wed, Feb 27, 2019 at 4:45 AM Devesh Sharma
> <devesh.sharma@broadcom.com> wrote:
> >
> > On Fri, Feb 22, 2019 at 4:55 AM Jason Gunthorpe <jgg@ziepe.ca> wrote:
> > >
> > > On Wed, Feb 20, 2019 at 04:21:02PM -0800, Matthew Wilcox wrote:
> > > > This driver doesn't look up the pointer that it stores, so this can
> > > > just be an IDA and save some memory.
> > > >
> > > > Signed-off-by: Matthew Wilcox <willy@infradead.org>
> > > > ---
> > > >  drivers/infiniband/hw/ocrdma/ocrdma_main.c | 16 +++++++---------
> > > >  1 file changed, 7 insertions(+), 9 deletions(-)
> > > >
> > > > diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > > > index 1f393842453a..b014eeffbcce 100644
> > > > --- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > > > +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > > > @@ -62,7 +62,7 @@ MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
> > > >  MODULE_AUTHOR("Emulex Corporation");
> > > >  MODULE_LICENSE("Dual BSD/GPL");
> > > >
> > > > -static DEFINE_IDR(ocrdma_dev_id);
> > > > +static DEFINE_IDA(ocrdma_dev_id);
> > > >
> > > >  void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
> > > >  {
> > > > @@ -302,12 +302,12 @@ static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
> > > >       }
> > > >       dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
> > > >       if (!dev->mbx_cmd)
> > > > -             goto idr_err;
> > > > +             goto ida_err;
> > > >
> > > >       memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
> > > > -     dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL);
> > > > +     dev->id = ida_alloc(&ocrdma_dev_id, GFP_KERNEL);
> > >
> > > WTF.. There are only three places where this id is used:
> > >  - A whole bunch of pr_* calls which *really* should be dev_* calls
> > >    with no ID (grrrr)
> > >  - It is passed to userspace in the ucontext udata, and userpace
> > >    ignores it (double grrrrr)
> > >  - It is used to form a name for request_irq (use the pci BDF)
> > >
> > > We should delete this thing :(
> > >
> >
> > Will send a patch to remove this.
>
> Devesh, will  a patch be coming?
>
Yeah Jason, I will send it this week.
> Thanks,
> Jason
Devesh Sharma April 8, 2019, 5:33 a.m. UTC | #5
On Mon, Apr 1, 2019 at 11:41 PM Devesh Sharma
<devesh.sharma@broadcom.com> wrote:
>
> On Fri, Mar 29, 2019 at 11:27 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
> >
> > On Wed, Feb 27, 2019 at 4:45 AM Devesh Sharma
> > <devesh.sharma@broadcom.com> wrote:
> > >
> > > On Fri, Feb 22, 2019 at 4:55 AM Jason Gunthorpe <jgg@ziepe.ca> wrote:
> > > >
> > > > On Wed, Feb 20, 2019 at 04:21:02PM -0800, Matthew Wilcox wrote:
> > > > > This driver doesn't look up the pointer that it stores, so this can
> > > > > just be an IDA and save some memory.
> > > > >
> > > > > Signed-off-by: Matthew Wilcox <willy@infradead.org>
> > > > > ---
> > > > >  drivers/infiniband/hw/ocrdma/ocrdma_main.c | 16 +++++++---------
> > > > >  1 file changed, 7 insertions(+), 9 deletions(-)
> > > > >
> > > > > diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > > > > index 1f393842453a..b014eeffbcce 100644
> > > > > --- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > > > > +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> > > > > @@ -62,7 +62,7 @@ MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
> > > > >  MODULE_AUTHOR("Emulex Corporation");
> > > > >  MODULE_LICENSE("Dual BSD/GPL");
> > > > >
> > > > > -static DEFINE_IDR(ocrdma_dev_id);
> > > > > +static DEFINE_IDA(ocrdma_dev_id);
> > > > >
> > > > >  void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
> > > > >  {
> > > > > @@ -302,12 +302,12 @@ static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
> > > > >       }
> > > > >       dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
> > > > >       if (!dev->mbx_cmd)
> > > > > -             goto idr_err;
> > > > > +             goto ida_err;
> > > > >
> > > > >       memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
> > > > > -     dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL);
> > > > > +     dev->id = ida_alloc(&ocrdma_dev_id, GFP_KERNEL);
> > > >
> > > > WTF.. There are only three places where this id is used:
> > > >  - A whole bunch of pr_* calls which *really* should be dev_* calls
> > > >    with no ID (grrrr)
> > > >  - It is passed to userspace in the ucontext udata, and userpace
> > > >    ignores it (double grrrrr)
> > > >  - It is used to form a name for request_irq (use the pci BDF)
> > > >
> > > > We should delete this thing :(
> > > >
> > >
> > > Will send a patch to remove this.
> >
> > Devesh, will  a patch be coming?
> >
> Yeah Jason, I will send it this week.
> > Thanks,
> > Jason
Hey Jason, still trying to test the patch, I will be sending this in a
day or two.
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
index 1f393842453a..b014eeffbcce 100644
--- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
+++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
@@ -62,7 +62,7 @@  MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
 MODULE_AUTHOR("Emulex Corporation");
 MODULE_LICENSE("Dual BSD/GPL");
 
-static DEFINE_IDR(ocrdma_dev_id);
+static DEFINE_IDA(ocrdma_dev_id);
 
 void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
 {
@@ -302,12 +302,12 @@  static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
 	}
 	dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
 	if (!dev->mbx_cmd)
-		goto idr_err;
+		goto ida_err;
 
 	memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
-	dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL);
+	dev->id = ida_alloc(&ocrdma_dev_id, GFP_KERNEL);
 	if (dev->id < 0)
-		goto idr_err;
+		goto ida_err;
 
 	status = ocrdma_init_hw(dev);
 	if (status)
@@ -345,8 +345,8 @@  static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
 	ocrdma_free_resources(dev);
 	ocrdma_cleanup_hw(dev);
 init_err:
-	idr_remove(&ocrdma_dev_id, dev->id);
-idr_err:
+	ida_free(&ocrdma_dev_id, dev->id);
+ida_err:
 	kfree(dev->mbx_cmd);
 	ib_dealloc_device(&dev->ibdev);
 	pr_err("%s() leaving. ret=%d\n", __func__, status);
@@ -355,8 +355,7 @@  static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
 
 static void ocrdma_remove_free(struct ocrdma_dev *dev)
 {
-
-	idr_remove(&ocrdma_dev_id, dev->id);
+	ida_free(&ocrdma_dev_id, dev->id);
 	kfree(dev->mbx_cmd);
 	ib_dealloc_device(&dev->ibdev);
 }
@@ -461,7 +460,6 @@  static void __exit ocrdma_exit_module(void)
 {
 	be_roce_unregister_driver(&ocrdma_drv);
 	ocrdma_rem_debugfs();
-	idr_destroy(&ocrdma_dev_id);
 }
 
 module_init(ocrdma_init_module);