Subject: Re: [PATCH net-next v2 02/15] idpf: add module register and probe functionality

From: Leon Romanovsky <[email-masked]>
Date: Thu, 13 Apr 2023 09:03:57 +0300

On Wed, Apr 12, 2023 at 04:10:18PM -0700, Tantilov, Emil S wrote:
> 
> 
> On 4/11/2023 5:36 AM, Leon Romanovsky wrote:
> > On Mon, Apr 10, 2023 at 06:13:41PM -0700, Pavan Kumar Linga wrote:
> > > From: Phani Burra <[email-masked]>
> > > 
> > > Add the required support to register IDPF PCI driver, as well as
> > > probe and remove call backs. Enable the PCI device and request
> > > the kernel to reserve the memory resources that will be used by the
> > > driver. Finally map the BAR0 address space.
> > > 
> > > PCI IDs table is intentionally left blank to prevent the kernel from
> > > probing the device with the incomplete driver. It will be added
> > > in the last patch of the series.
> > > 
> > > Signed-off-by: Phani Burra <[email-masked]>
> > > Co-developed-by: Alan Brady <[email-masked]>
> > > Signed-off-by: Alan Brady <[email-masked]>
> > > Co-developed-by: Madhu Chittim <[email-masked]>
> > > Signed-off-by: Madhu Chittim <[email-masked]>
> > > Co-developed-by: Shailendra Bhatnagar <[email-masked]>
> > > Signed-off-by: Shailendra Bhatnagar <[email-masked]>
> > > Co-developed-by: Pavan Kumar Linga <[email-masked]>
> > > Signed-off-by: Pavan Kumar Linga <[email-masked]>
> > > Reviewed-by: Sridhar Samudrala <[email-masked]>
> > > Reviewed-by: Willem de Bruijn <[email-masked]>
> > > ---
> > >   drivers/net/ethernet/intel/Kconfig            | 11 +++
> > >   drivers/net/ethernet/intel/Makefile           |  1 +
> > >   drivers/net/ethernet/intel/idpf/Makefile      | 10 ++
> > >   drivers/net/ethernet/intel/idpf/idpf.h        | 27 ++++++
> > >   .../net/ethernet/intel/idpf/idpf_controlq.h   | 14 +++
> > >   drivers/net/ethernet/intel/idpf/idpf_lib.c    | 96 +++++++++++++++++++
> > >   drivers/net/ethernet/intel/idpf/idpf_main.c   | 70 ++++++++++++++
> > >   7 files changed, 229 insertions(+)
> > >   create mode 100644 drivers/net/ethernet/intel/idpf/Makefile
> > >   create mode 100644 drivers/net/ethernet/intel/idpf/idpf.h
> > >   create mode 100644 drivers/net/ethernet/intel/idpf/idpf_controlq.h
> > >   create mode 100644 drivers/net/ethernet/intel/idpf/idpf_lib.c
> > >   create mode 100644 drivers/net/ethernet/intel/idpf/idpf_main.c
> > 
> > <...>

<...>

> > > +/**
> > > + * idpf_probe - Device initialization routine
> > > + * @pdev: PCI device information struct
> > > + * @ent: entry in idpf_pci_tbl
> > > + *
> > > + * Returns 0 on success, negative on failure
> > > + */
> > > +static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> > > +{
> > > +	struct idpf_adapter *adapter;
> > > +
> > > +	adapter = devm_kzalloc(&pdev->dev, sizeof(*adapter), GFP_KERNEL);
> > 
> > Why devm_kzalloc() and not kzalloc?
> It provides managed memory allocation on probe, which seems to be the
> preferred method in that case.

I don't think so, as PCI probe/remove has very clear lifetime model and
doesn't need garbage collection memory logic. In general, it is better
to avoid devm_*() APIs as they hide error unwind flows.

Thanks