]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
net: enetc: add generic helper to initialize SR-IOV resources
authorWei Fang <wei.fang@nxp.com>
Fri, 22 May 2026 09:24:36 +0000 (17:24 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 26 May 2026 11:20:13 +0000 (13:20 +0200)
commit250069ef0df3e1cf996f03c62eb96d1159cf8166
treedc931bcdd9e6b2693d406d4c70ab796002591e7b
parent6bdc3144c0dc737915450c0cd9641ac64c53d714
net: enetc: add generic helper to initialize SR-IOV resources

The upcoming ENETC v4 PF driver will support SR-IOV, and its logic for
initializing VF resources is identical to the existing ENETC v1 PF
implementation. To avoid code duplication across PF drivers, factor out
the common SR-IOV initialization logic into the enetc-pf-common driver.

Add enetc_init_sriov_resources() to handle:
- Querying the total number of VFs supported by the device via
  pci_sriov_get_totalvfs()
- Allocating memory for the VF state array (struct enetc_vf_state)

The implementation uses devm_kcalloc() instead of kzalloc() to simplify
memory management. This automatically frees VF state memory when the PF
device is removed, eliminating the need for explicit cleanup in error
and remove paths.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
Link: https://patch.msgid.link/20260522092438.1264020-11-wei.fang@nxp.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/freescale/enetc/enetc_pf.c
drivers/net/ethernet/freescale/enetc/enetc_pf_common.c
drivers/net/ethernet/freescale/enetc/enetc_pf_common.h