mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Jia-Ju Bai <baijiaju1990@163.com>
Cc: mcgrof@kernel.org, gregkh@linuxfoundation.org, perex@perex.cz,
	tiwai@suse.com, dhowells@redhat.com, bhumirks@gmail.com,
	fabf@skynet.be, alsa-devel@alsa-project.org,
	linux-kernel@vger.kernel.org
Subject: Re: [alsa-devel] [PATCH] sound/pci/riptide or drivers/base/firmware:   Fix a possible sleep-in-atomic bug
Date: Mon, 09 Oct 2017 08:43:58 +0200	[thread overview]
Message-ID: <s5h4lr8om6p.wl-tiwai@suse.de> (raw)
In-Reply-To: <1507515196-3241-1-git-send-email-baijiaju1990@163.com>

On Mon, 09 Oct 2017 04:13:16 +0200,
Jia-Ju Bai wrote:
> 
> The riptide driver may sleep under a spinlock, and the function call path is:
> snd_riptide_prepare (acquire the spinlock)
>   setsampleformat
>     sendcmd
>       riptide_reset
>         try_to_load_firmware
>           request_firmware
>             _request_firmware (drivers/base/firmware_class.c)
>               _request_firmware_prepare
>                 kzalloc(GFP_KERNEL) --> may sleep
> 
> To fix it, GFP_KERNEL is replaced with GFP_ATOMIC in _request_firmware_prepare.
> This bug is found by my static analysis tool and my code review.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>

This doesn't happen.  try_to_load_firmware() aborts before the
request_firmware() call when chip == NULL, which is the case from
sendcmd().

And, moreover, the call of request_firmware() itself inside the
spinlock would be already buggy.


thanks,

Takashi

> ---
>  drivers/base/firmware_class.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index 4b57cf5..d89f676 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -1138,7 +1138,7 @@ static inline void kill_pending_fw_fallback_reqs(bool only_kill_custom) { }
>  	struct firmware_buf *buf;
>  	int ret;
>  
> -	*firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
> +	*firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_ATOMIC);
>  	if (!firmware) {
>  		dev_err(device, "%s: kmalloc(struct firmware) failed\n",
>  			__func__);
> -- 
> 1.7.9.5
> 
> 
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
> 

      reply	other threads:[~2017-10-09  6:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-09  2:13 Jia-Ju Bai
2017-10-09  6:43 ` Takashi Iwai [this message]

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=s5h4lr8om6p.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=baijiaju1990@163.com \
    --cc=bhumirks@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=fabf@skynet.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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

all inboxes | Powered by JetHome®