From: Paolo Perego <pperego@suse.de>
To: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: Dave Penkler <dpenkler@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Dan Carpenter <dan.carpenter@linaro.org>,
Kees Bakker <kees@ijzerbout.nl>, Paolo Perego <pperego@suse.de>,
Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH v2] staging:gpib: Fix a dereference before null check issue
Date: Thu, 21 Nov 2024 16:22:21 +0100 [thread overview]
Message-ID: <20241121152221.6415-1-pperego@suse.de> (raw)
This commit fixes a dereference before null check issue discovered by
Coverity (CID 1601566).
The check at line 1450 suggests that a_priv can be NULL, however it has
been dereferenced before, in the interface_to_usbdev() call.
After a discussion, the NULL check is useless because private data is allocated
in attach routine and freed in detach routine, so in detach routine the pointer
has to be not NULL for sure.
Signed-off-by: Paolo Perego <pperego@suse.de>
Fixes: Removes a useless NULL check
---
v2:
* After a discussion, we agreed the NULL check is useless because private data
is freed in detach routine and allocated while attaching. For such a reason,
the pointer has to be not NULL while detaching the device
.../gpib/agilent_82357a/agilent_82357a.c | 20 +++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
index bf05fb4a736b..e940429dea19 100644
--- a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+++ b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
@@ -1447,17 +1447,17 @@ static void agilent_82357a_detach(gpib_board_t *board)
a_priv = board->private_data;
usb_dev = interface_to_usbdev(a_priv->bus_interface);
- if (a_priv) {
- if (a_priv->bus_interface) {
- agilent_82357a_go_idle(board);
- usb_set_intfdata(a_priv->bus_interface, NULL);
- }
- mutex_lock(&a_priv->control_alloc_lock);
- mutex_lock(&a_priv->bulk_alloc_lock);
- mutex_lock(&a_priv->interrupt_alloc_lock);
- agilent_82357a_cleanup_urbs(a_priv);
- agilent_82357a_free_private(a_priv);
+
+ if (a_priv->bus_interface) {
+ agilent_82357a_go_idle(board);
+ usb_set_intfdata(a_priv->bus_interface, NULL);
}
+
+ mutex_lock(&a_priv->control_alloc_lock);
+ mutex_lock(&a_priv->bulk_alloc_lock);
+ mutex_lock(&a_priv->interrupt_alloc_lock);
+ agilent_82357a_cleanup_urbs(a_priv);
+ agilent_82357a_free_private(a_priv);
dev_info(&usb_dev->dev, "%s: detached\n", __func__);
mutex_unlock(&agilent_82357a_hotplug_lock);
}
--
2.47.0
next reply other threads:[~2024-11-21 15:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-21 15:22 Paolo Perego [this message]
2024-11-21 18:55 ` [PATCH v2] staging:gpib: Fix a dereference before null check issue Dan Carpenter
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=20241121152221.6415-1-pperego@suse.de \
--to=pperego@suse.de \
--cc=arnd@arndb.de \
--cc=dan.carpenter@linaro.org \
--cc=dpenkler@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=kees@ijzerbout.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox