From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753924AbdJIGoD (ORCPT ); Mon, 9 Oct 2017 02:44:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:38971 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753823AbdJIGoB (ORCPT ); Mon, 9 Oct 2017 02:44:01 -0400 Date: Mon, 09 Oct 2017 08:43:58 +0200 Message-ID: From: Takashi Iwai To: Jia-Ju Bai 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 In-Reply-To: <1507515196-3241-1-git-send-email-baijiaju1990@163.com> References: <1507515196-3241-1-git-send-email-baijiaju1990@163.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 >