From: Niklas Cassel <cassel@kernel.org>
To: Alok Tiwari <alok.a.tiwari@oracle.com>
Cc: den@valinux.co.jp, jdmason@kudzu.us, dave.jiang@intel.com,
allenbh@gmail.com, mani@kernel.org, kwilczynski@kernel.org,
kishon@kernel.org, bhelgaas@google.com, ntb@lists.linux.dev,
linux-pci@vger.kernel.org, alok.a.tiwarilinux@gmail.com
Subject: Re: [PATCH] PCI: endpoint: pci-epf-vntb: Check pci_epc_get_features() return value
Date: Tue, 24 Feb 2026 14:38:33 +0100 [thread overview]
Message-ID: <aZ2p08thDzZdSdNc@ryzen> (raw)
In-Reply-To: <20260224133112.1356612-1-alok.a.tiwari@oracle.com>
On Tue, Feb 24, 2026 at 05:31:03AM -0800, Alok Tiwari wrote:
> pci_epc_get_features() may return NULL for invalid function numbers or
> if the EPC driver does not provide feature information. Other EPF drivers
> such as pci-epf-ntb.c and pci-epf-test.c already handle this case.
>
> Add a defensive NULL check to avoid a potential NULL pointer dereference.
>
> No functional change intended.
>
> Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
I think a better solution is to do like pci-epf-test.c, which calls
pci_epc_get_features() once in .bind() and if it fails, it fails bind(),
if it returns non-NULL, it caches the result:
https://github.com/torvalds/linux/blob/v6.19/drivers/pci/endpoint/functions/pci-epf-test.c#L1112-L1123
That way, all other functions do not need to NULL check
pci_epc_get_features(). (Instead it can use the cached value)
pci-epf-vntb.c should probably do something similar to avoid sprinkling
NULL checks all over pci-epf-vntb.c.
And, if there are any existing
if (!epc_features) return -EINVAL;
they can be removed once you've added the check in .bind().
Kind regards,
Niklas
next prev parent reply other threads:[~2026-02-24 13:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 13:31 [PATCH] PCI: endpoint: pci-epf-vntb: Check pci_epc_get_features() return value Alok Tiwari
2026-02-24 13:38 ` Niklas Cassel [this message]
2026-02-25 5:21 ` Koichiro Den
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aZ2p08thDzZdSdNc@ryzen \
--to=cassel@kernel.org \
--cc=allenbh@gmail.com \
--cc=alok.a.tiwari@oracle.com \
--cc=alok.a.tiwarilinux@gmail.com \
--cc=bhelgaas@google.com \
--cc=dave.jiang@intel.com \
--cc=den@valinux.co.jp \
--cc=jdmason@kudzu.us \
--cc=kishon@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mani@kernel.org \
--cc=ntb@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.