linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] memstick/ms_block: Add check for alloc_ordered_workqueue
@ 2022-11-26  1:25 Jiasheng Jiang
  2022-11-26  8:01 ` Dan Carpenter
  2022-11-29 12:54 ` Ulf Hansson
  0 siblings, 2 replies; 4+ messages in thread
From: Jiasheng Jiang @ 2022-11-26  1:25 UTC (permalink / raw)
  To: error27, maximlevitsky, oakad, ulf.hansson, christophe.jaillet,
	axboe, hare
  Cc: linux-mmc, linux-kernel, Jiasheng Jiang

As the alloc_ordered_workqueue may return NULL pointer,
it should be better to add check for the return
value.
Moreover, the msb->io_queue should be freed if error occurs later.

Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog:

v1 -> v2:

1. Assign error number to rc if alloc_ordered_workqueue fails.
2. Free msb->io_queue if error occurs later.
---
 drivers/memstick/core/ms_block.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index ba8414519515..04115cd92433 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -2116,6 +2116,11 @@ static int msb_init_disk(struct memstick_dev *card)
 	dbg("Set total disk size to %lu sectors", capacity);
 
 	msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM);
+	if (!msb->io_queue) {
+		rc = -ENOMEM;
+		goto out_cleanup_disk;
+	}
+
 	INIT_WORK(&msb->io_work, msb_io_work);
 	sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1);
 
@@ -2125,10 +2130,12 @@ static int msb_init_disk(struct memstick_dev *card)
 	msb_start(card);
 	rc = device_add_disk(&card->dev, msb->disk, NULL);
 	if (rc)
-		goto out_cleanup_disk;
+		goto out_destroy_workqueue;
 	dbg("Disk added");
 	return 0;
 
+out_destroy_workqueue:
+	destroy_workqueue(msb->io_queue);
 out_cleanup_disk:
 	put_disk(msb->disk);
 out_free_tag_set:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] memstick/ms_block: Add check for alloc_ordered_workqueue
  2022-11-26  1:25 [PATCH v2] memstick/ms_block: Add check for alloc_ordered_workqueue Jiasheng Jiang
@ 2022-11-26  8:01 ` Dan Carpenter
  2022-11-28 14:45   ` Ulf Hansson
  2022-11-29 12:54 ` Ulf Hansson
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2022-11-26  8:01 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: maximlevitsky, oakad, ulf.hansson, christophe.jaillet, axboe,
	hare, linux-mmc, linux-kernel

On Sat, Nov 26, 2022 at 09:25:58AM +0800, Jiasheng Jiang wrote:
> As the alloc_ordered_workqueue may return NULL pointer,
> it should be better to add check for the return
> value.
> Moreover, the msb->io_queue should be freed if error occurs later.
> 
> Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> Changelog:
> 
> v1 -> v2:
> 
> 1. Assign error number to rc if alloc_ordered_workqueue fails.
> 2. Free msb->io_queue if error occurs later.
> ---

My other question about this driver, not really directed to you but to
anyone on the list is where the final destroy_workqueue(msb->io_queue)
is when we unload the driver.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] memstick/ms_block: Add check for alloc_ordered_workqueue
  2022-11-26  8:01 ` Dan Carpenter
@ 2022-11-28 14:45   ` Ulf Hansson
  0 siblings, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2022-11-28 14:45 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jiasheng Jiang, maximlevitsky, oakad, christophe.jaillet, axboe,
	hare, linux-mmc, linux-kernel

On Sat, 26 Nov 2022 at 09:01, Dan Carpenter <error27@gmail.com> wrote:
>
> On Sat, Nov 26, 2022 at 09:25:58AM +0800, Jiasheng Jiang wrote:
> > As the alloc_ordered_workqueue may return NULL pointer,
> > it should be better to add check for the return
> > value.
> > Moreover, the msb->io_queue should be freed if error occurs later.
> >
> > Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
> > Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> > ---
> > Changelog:
> >
> > v1 -> v2:
> >
> > 1. Assign error number to rc if alloc_ordered_workqueue fails.
> > 2. Free msb->io_queue if error occurs later.
> > ---
>
> My other question about this driver, not really directed to you but to
> anyone on the list is where the final destroy_workqueue(msb->io_queue)
> is when we unload the driver.

Good point, it's simply missing somewhere in the path of the
->remove() callback.

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] memstick/ms_block: Add check for alloc_ordered_workqueue
  2022-11-26  1:25 [PATCH v2] memstick/ms_block: Add check for alloc_ordered_workqueue Jiasheng Jiang
  2022-11-26  8:01 ` Dan Carpenter
@ 2022-11-29 12:54 ` Ulf Hansson
  1 sibling, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2022-11-29 12:54 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: error27, maximlevitsky, oakad, christophe.jaillet, axboe, hare,
	linux-mmc, linux-kernel

On Sat, 26 Nov 2022 at 02:26, Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
>
> As the alloc_ordered_workqueue may return NULL pointer,
> it should be better to add check for the return
> value.
> Moreover, the msb->io_queue should be freed if error occurs later.
>
> Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>

Applied for next (replaced the earlier applied v1 with v2), thanks!

Kind regards
Uffe


> ---
> Changelog:
>
> v1 -> v2:
>
> 1. Assign error number to rc if alloc_ordered_workqueue fails.
> 2. Free msb->io_queue if error occurs later.
> ---
>  drivers/memstick/core/ms_block.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
> index ba8414519515..04115cd92433 100644
> --- a/drivers/memstick/core/ms_block.c
> +++ b/drivers/memstick/core/ms_block.c
> @@ -2116,6 +2116,11 @@ static int msb_init_disk(struct memstick_dev *card)
>         dbg("Set total disk size to %lu sectors", capacity);
>
>         msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM);
> +       if (!msb->io_queue) {
> +               rc = -ENOMEM;
> +               goto out_cleanup_disk;
> +       }
> +
>         INIT_WORK(&msb->io_work, msb_io_work);
>         sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1);
>
> @@ -2125,10 +2130,12 @@ static int msb_init_disk(struct memstick_dev *card)
>         msb_start(card);
>         rc = device_add_disk(&card->dev, msb->disk, NULL);
>         if (rc)
> -               goto out_cleanup_disk;
> +               goto out_destroy_workqueue;
>         dbg("Disk added");
>         return 0;
>
> +out_destroy_workqueue:
> +       destroy_workqueue(msb->io_queue);
>  out_cleanup_disk:
>         put_disk(msb->disk);
>  out_free_tag_set:
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-29 12:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26  1:25 [PATCH v2] memstick/ms_block: Add check for alloc_ordered_workqueue Jiasheng Jiang
2022-11-26  8:01 ` Dan Carpenter
2022-11-28 14:45   ` Ulf Hansson
2022-11-29 12:54 ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).