From: Dan Carpenter <dan.carpenter@linaro.org>
To: Ma Ke <make24@iscas.ac.cn>
Cc: dpenkler@gmail.com, gregkh@linuxfoundation.org,
matchstick@neverthere.org,
dominik.karol.piatkowski@protonmail.com, arnd@arndb.de,
nichen@iscas.ac.cn, paul.retourne@orange.fr,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] staging: gpib: Fix device reference leak in fmh_gpib driver
Date: Mon, 22 Sep 2025 14:28:44 +0300 [thread overview]
Message-ID: <aNEy7LsnKa50Pq3c@stanley.mountain> (raw)
In-Reply-To: <20250922084512.9174-1-make24@iscas.ac.cn>
On Mon, Sep 22, 2025 at 04:45:12PM +0800, Ma Ke wrote:
> The fmh_gpib driver contains a device reference count leak in
> fmh_gpib_attach_impl() where driver_find_device() increases the
> reference count of the device by get_device() when matching but this
> reference is not properly decreased. Add put_device() in
> fmh_gpib_attach_impl() and add put_device() in fmh_gpib_detach(),
> which ensures that the reference count of the device is correctly
> managed.
>
> Found by code review.
>
> Cc: stable@vger.kernel.org
> Fixes: 8e4841a0888c ("staging: gpib: Add Frank Mori Hess FPGA PCI GPIB driver")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> Changes in v2:
> - modified the free operations as suggestions. Thanks for dan carpenter's instructions.
> ---
Actually, it turns out that this isn't the right approach. Sorry.
This will introduce double frees.
The caller looks like this:
drivers/staging/gpib/common/iblib.c
204 int ibonline(struct gpib_board *board)
205 {
206 int retval;
207
208 if (board->online)
209 return -EBUSY;
210 if (!board->interface)
211 return -ENODEV;
212 retval = gpib_allocate_board(board);
213 if (retval < 0)
214 return retval;
215
216 board->dev = NULL;
217 board->local_ppoll_mode = 0;
218 retval = board->interface->attach(board, &board->config);
219 if (retval < 0) {
220 board->interface->detach(board);
So if the attach() fails, we call ->detach() which works.
221 return retval;
222 }
It's weird because the fmh_gpib_pci_detach() function does have a
put_device() in it:
if (board->dev)
pci_dev_put(to_pci_dev(board->dev));
^^^^^^^^^^^
The detach functions are really similar...
regards,
dan carpenter
next prev parent reply other threads:[~2025-09-22 11:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-22 8:45 [PATCH v2] staging: gpib: Fix device reference leak in fmh_gpib driver Ma Ke
2025-09-22 11:28 ` Dan Carpenter [this message]
2025-09-22 13:36 ` Ma Ke
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=aNEy7LsnKa50Pq3c@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=dominik.karol.piatkowski@protonmail.com \
--cc=dpenkler@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=make24@iscas.ac.cn \
--cc=matchstick@neverthere.org \
--cc=nichen@iscas.ac.cn \
--cc=paul.retourne@orange.fr \
--cc=stable@vger.kernel.org \
/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.