linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: core: Don't destroy master queue if we fail to create it
@ 2014-05-01 17:49 Mark Brown
       [not found] ` <1398966567-5182-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2014-05-01 17:49 UTC (permalink / raw)
  To: Ricardo Ribalda Delgado, Geert Uytterhoeven
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linaro-kerne-cunTk1MwBs8s++Sfvej+rw, Mark Brown

From: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

If we fail to create the master queue for some reason we should not attempt
to clean it up since attempting to stop a kthread that was not created will
hang and it's just generally bad practice. Unfortunately at present we call
spi_destroy_queue() even in cases where the creation fails.

Fix this by fixing the error handling in spi_master_initialize_queue() so
that we only flag the master as queued or destroy the queue if creation
succeeded. The change to the flag is done since the general master
cleanup uses this to destroy the queue.

Reported-by: Ricardo Ribalda Delgado <ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---

This has been compile tested only but it should hopefully be more robust
in the long term than just skipping the queue deletion inside the
destructor.

 drivers/spi/spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 38ba75a..bc42e27 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1151,7 +1151,6 @@ static int spi_master_initialize_queue(struct spi_master *master)
 {
 	int ret;
 
-	master->queued = true;
 	master->transfer = spi_queued_transfer;
 	if (!master->transfer_one_message)
 		master->transfer_one_message = spi_transfer_one_message;
@@ -1162,6 +1161,7 @@ static int spi_master_initialize_queue(struct spi_master *master)
 		dev_err(&master->dev, "problem initializing queue\n");
 		goto err_init_queue;
 	}
+	master->queued = true;
 	ret = spi_start_queue(master);
 	if (ret) {
 		dev_err(&master->dev, "problem starting queue\n");
@@ -1171,8 +1171,8 @@ static int spi_master_initialize_queue(struct spi_master *master)
 	return 0;
 
 err_start_queue:
-err_init_queue:
 	spi_destroy_queue(master);
+err_init_queue:
 	return ret;
 }
 
-- 
1.9.2

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] spi: core: Don't destroy master queue if we fail to create it
       [not found] ` <1398966567-5182-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2014-05-01 18:55   ` Geert Uytterhoeven
       [not found]     ` <CAMuHMdXwX5He07h-peVPwgGYHUrPF5V7r9uH7s8BaaaFHMnQxw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2014-05-01 18:55 UTC (permalink / raw)
  To: Mark Brown
  Cc: Ricardo Ribalda Delgado, linux-spi,
	linaro-kerne-cunTk1MwBs8s++Sfvej+rw, Mark Brown

On Thu, May 1, 2014 at 7:49 PM, Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> From: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
>
> If we fail to create the master queue for some reason we should not attempt
> to clean it up since attempting to stop a kthread that was not created will
> hang and it's just generally bad practice. Unfortunately at present we call
> spi_destroy_queue() even in cases where the creation fails.
>
> Fix this by fixing the error handling in spi_master_initialize_queue() so
> that we only flag the master as queued or destroy the queue if creation
> succeeded. The change to the flag is done since the general master
> cleanup uses this to destroy the queue.
>
> Reported-by: Ricardo Ribalda Delgado <ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
>
> This has been compile tested only but it should hopefully be more robust
> in the long term than just skipping the queue deletion inside the
> destructor.
>
>  drivers/spi/spi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 38ba75a..bc42e27 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1151,7 +1151,6 @@ static int spi_master_initialize_queue(struct spi_master *master)
>  {
>         int ret;
>
> -       master->queued = true;
>         master->transfer = spi_queued_transfer;
>         if (!master->transfer_one_message)
>                 master->transfer_one_message = spi_transfer_one_message;
> @@ -1162,6 +1161,7 @@ static int spi_master_initialize_queue(struct spi_master *master)
>                 dev_err(&master->dev, "problem initializing queue\n");
>                 goto err_init_queue;

You can just "return ret;" here...

>         }
> +       master->queued = true;
>         ret = spi_start_queue(master);
>         if (ret) {
>                 dev_err(&master->dev, "problem starting queue\n");
> @@ -1171,8 +1171,8 @@ static int spi_master_initialize_queue(struct spi_master *master)
>         return 0;
>
>  err_start_queue:
> -err_init_queue:
>         spi_destroy_queue(master);
> +err_init_queue:

... and kill the err_init_queue label.

>         return ret;
>  }

Apart from that:
Acked-by: Geert Uytterhoeven <geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] spi: core: Don't destroy master queue if we fail to create it
       [not found]     ` <CAMuHMdXwX5He07h-peVPwgGYHUrPF5V7r9uH7s8BaaaFHMnQxw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-05-01 19:03       ` Mark Brown
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2014-05-01 19:03 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Ricardo Ribalda Delgado, linux-spi,
	linaro-kerne-cunTk1MwBs8s++Sfvej+rw

[-- Attachment #1: Type: text/plain, Size: 961 bytes --]

On Thu, May 01, 2014 at 08:55:42PM +0200, Geert Uytterhoeven wrote:
> On Thu, May 1, 2014 at 7:49 PM, Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> > From: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

> > @@ -1162,6 +1161,7 @@ static int spi_master_initialize_queue(struct spi_master *master)
> >                 dev_err(&master->dev, "problem initializing queue\n");
> >                 goto err_init_queue;

> You can just "return ret;" here...

> >  err_start_queue:
> > -err_init_queue:
> >         spi_destroy_queue(master);
> > +err_init_queue:

> ... and kill the err_init_queue label.

Yeah, I know.  It's a stylistic thing - I tend to prefer to always use
labels if they're used at all in a function even if we could return
directly since it's more consistent.  Not that I'm 100% consistent about
that.

> Apart from that:
> Acked-by: Geert Uytterhoeven <geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>

Thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2014-05-01 19:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-01 17:49 [PATCH] spi: core: Don't destroy master queue if we fail to create it Mark Brown
     [not found] ` <1398966567-5182-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-05-01 18:55   ` Geert Uytterhoeven
     [not found]     ` <CAMuHMdXwX5He07h-peVPwgGYHUrPF5V7r9uH7s8BaaaFHMnQxw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-05-01 19:03       ` Mark Brown

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).