From: Greg KH <gregkh@linuxfoundation.org>
To: Shyam Sunder Reddy Padira <shyamsunderreddypadira@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev
Subject: Re: [PATCH] staging: vme_user: check find_bridge() return value
Date: Mon, 11 May 2026 09:46:26 +0200 [thread overview]
Message-ID: <2026051125-cost-calculus-2a6d@gregkh> (raw)
In-Reply-To: <20260505205746.227144-1-shyamsunderreddypadira@gmail.com>
On Wed, May 06, 2026 at 02:27:46AM +0530, Shyam Sunder Reddy Padira wrote:
> find_bridge() returns NULL when no matching bridge is found
> for a given resource. Some call sites dereference the return
> value without verifying it is non-NULL.
>
> Add NULL checks before use to avoid potentail NULL pointer
> dereferences.
>
> Signed-off-by: Shyam Sunder Reddy Padira <shyamsunderreddypadira@gmail.com>
> ---
> drivers/staging/vme_user/vme.c | 63 ++++++++++++++++++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
> diff --git a/drivers/staging/vme_user/vme.c b/drivers/staging/vme_user/vme.c
> index b5c66b66ce32..2ed2f1fe502f 100644
> --- a/drivers/staging/vme_user/vme.c
> +++ b/drivers/staging/vme_user/vme.c
> @@ -82,6 +82,9 @@ void *vme_alloc_consistent(struct vme_resource *resource, size_t size,
> {
> struct vme_bridge *bridge = find_bridge(resource);
>
> + if (!bridge)
> + return NULL;
> +
> if (!bridge->alloc_consistent) {
> dev_err(bridge->parent,
> "alloc_consistent not supported by bridge %s\n",
> @@ -107,6 +110,9 @@ void vme_free_consistent(struct vme_resource *resource, size_t size,
> {
> struct vme_bridge *bridge = find_bridge(resource);
>
> + if (!bridge)
> + return;
> +
> if (!bridge->free_consistent) {
> dev_err(bridge->parent,
> "free_consistent not supported by bridge %s\n",
> @@ -136,6 +142,9 @@ size_t vme_get_size(struct vme_resource *resource)
> dma_addr_t buf_base;
> u32 aspace, cycle, dwidth;
>
> + if (!bridge)
> + return 0;
This is an error, why not return a error?
> +
> switch (resource->type) {
> case VME_MASTER:
> retval = vme_master_get(resource, &enabled, &base, &size,
> @@ -332,6 +341,9 @@ int vme_slave_set(struct vme_resource *resource, int enabled,
> struct vme_slave_resource *image;
> int retval;
>
> + if (!bridge)
> + return 0;
Same here.
Also, can this ever actually happen? Given that the code seems to work
just fine, if you look at the callers, the function does not seem to
ever be able to return NULL, so be careful of adding checks that are
never actually needed.
thanks,
greg k-h
next prev parent reply other threads:[~2026-05-11 7:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-05 20:57 [PATCH] staging: vme_user: check find_bridge() return value Shyam Sunder Reddy Padira
2026-05-11 7:46 ` Greg KH [this message]
2026-05-11 16:54 ` Shyam Sunder Reddy Padira
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=2026051125-cost-calculus-2a6d@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=shyamsunderreddypadira@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox