Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1796961ybl; Thu, 19 Dec 2019 03:11:57 -0800 (PST) X-Google-Smtp-Source: APXvYqyC4aodjWv9MpZqotQHBtx1Ka0rAAnOdI5nUJR1D4EgU7z/YhQqm2ZZfL/8wzuo0ux8SO1z X-Received: by 2002:a05:6830:1cd3:: with SMTP id p19mr6215877otg.118.1576753917406; Thu, 19 Dec 2019 03:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576753917; cv=none; d=google.com; s=arc-20160816; b=kWUQbUE1w+Jcf+0D4819kau1Y1BgLdk7RJPDhVOkLEq1JyXGpSwG/8lTDeom8O8NXX 94prFPMA8GAMy/sOHYD83lIYRmISq4j8waAUrHH4JjRMum8/8tLZITWnCtUXp0qx0bwa IeXWRd648au8+nfICOPW0J92pO9+S8x+wtTrlSRI9B8uhSe3NAk0e5NwijK76uGOT8EY g0l2EvaFQvSYpByisnu+buIaNwP7H3yJkqMH8VQSkfn+kH/+BYj6rJx3/vC2fo25v2Yq VVuqmVztuJv17T/9JeFXxJ2ZiwCFrgX4ePKoI6dNu2jdAWpucXrzvs8c6ty3TCrqwZrH 8Dxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=SJiLbsEyOxS8sGorfLAOU4xJKF3nGQf0Amv/oVqLTpM=; b=iq2MarS1KYgdY05nqKL2mdbDUJMVXffEIesbRPomMf3cEqj33HXSoyB5b2xoFlCMq0 +gTdpUw+ESy/Q/3AbezvaTAEyaCp2VKSGUDc0wLnevqlwwE9NP/5zO+hqph4Uo0LeYJE eVpCMOoYNkzePKK9zAj27DQgoJ137vQ7cWFWhCDMst67EPI14nQQDESeUdGyLtNBSSzW XzxIfF6kRPuY3t6U3jjS7h0Ywbeyvh9zVFsQujqp1o9rqQcvQ8HZjm9yuz5Y7qSjWkya u2Emq+493rcK//h0AckPvSOPpl9e6QlTKBQJCpVcXMMKhr3XND8YrfekKz9GUL+mv6z5 Ee5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=dm+K4tCb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d17si2281527oib.174.2019.12.19.03.11.44; Thu, 19 Dec 2019 03:11:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=dm+K4tCb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726725AbfLSLKl (ORCPT + 99 others); Thu, 19 Dec 2019 06:10:41 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:35091 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726695AbfLSLKk (ORCPT ); Thu, 19 Dec 2019 06:10:40 -0500 Received: by mail-qt1-f196.google.com with SMTP id e12so4724240qto.2 for ; Thu, 19 Dec 2019 03:10:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=SJiLbsEyOxS8sGorfLAOU4xJKF3nGQf0Amv/oVqLTpM=; b=dm+K4tCbb0SMvVMAS0DtrlIoPpBOu2T6hGIWa5e7atlrpaJCuIes0zfCXr3T5q7nLs kCwvc1d1itkC2VjSGzn3qrkyXgtOkoW08YOAl0CKzd/ah4172kFKW0LPoSUpbNkC2RGH 0P1kMf7/C/K9ig+o3VoEDpj/Q6kZT6fARM7OvSkMLaGKMQCDctwCGNw0G5H/PhVzOrT9 rCj0biTH7OWie/kAr3zTxePDI0/x1GwlbSYqrOXqbTzt8WRXgp4EniJHAr8AS/WK2mbX SvOY2W2dEstfqvrnKwKZg0hg5YNAa4d+UqyBTP0C2ybhrvg78unmXrWyrRHP9DhjDsGx teUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=SJiLbsEyOxS8sGorfLAOU4xJKF3nGQf0Amv/oVqLTpM=; b=PFkRgCVkqPQ5cfmFljKVQbooTF5UYtTGbMRMBinX/pns63I4EZStul+pRo/hu/FBqM g5rHAXCY9DzJnBqdRmB3NuqkRHNWlykvkeTpXwJZ2HY2oNwIHoTROOdk4Ip5LbO5aTSv LWjmCL5ait6AvU/CLBLnx5aNK3fzI8OS+lIuHAQ9s5MBgF0dIYezZtfITFsR5JLrkpea lidvRjVdmXnDywVDFvMTFE8NaPWqXB/Pv3nbVtTLgRiRKYerw1U1WJBgbpJXPEJl0zE4 g6Gxwsu4D29GpIQbk0IvQHIbX2WGDlg6nlVnGCcQOPxL03ZhCR4a7uLY5uKcVg7xK3Kn fmQA== X-Gm-Message-State: APjAAAXxcg5QFlPICSeNZWIZWhe5E0vchZQFCCOIdzd6oYXogGxyCJGV amloZTfkE6HWrRU/JbezBnEQFEPNvsuabCU+vp0MsA== X-Received: by 2002:aed:3b6e:: with SMTP id q43mr6255037qte.57.1576753839903; Thu, 19 Dec 2019 03:10:39 -0800 (PST) MIME-Version: 1.0 References: <20191218132551.10537-1-baijiaju1990@gmail.com> In-Reply-To: <20191218132551.10537-1-baijiaju1990@gmail.com> From: Bartosz Golaszewski Date: Thu, 19 Dec 2019 12:10:29 +0100 Message-ID: Subject: Re: [PATCH 1/2] gpio: gpio-grgpio: fix possible sleep-in-atomic-context bugs in grgpio_remove() To: Jia-Ju Bai Cc: Linus Walleij , linux-gpio , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org =C5=9Br., 18 gru 2019 o 14:26 Jia-Ju Bai napisa=C5= =82(a): > > The driver may sleep while holding a spinlock. > The function call path (from bottom to top) in Linux 4.19 is: > > drivers/gpio/gpiolib-sysfs.c, 796: > mutex_lock in gpiochip_sysfs_unregister > drivers/gpio/gpiolib.c, 1455: > gpiochip_sysfs_unregister in gpiochip_remove > drivers/gpio/gpio-grgpio.c, 460: > gpiochip_remove in grgpio_remove > drivers/gpio/gpio-grgpio.c, 449: > _raw_spin_lock_irqsave in grgpio_remove > > kernel/irq/irqdomain.c, 243: > mutex_lock in irq_domain_remove > drivers/gpio/gpio-grgpio.c, 463: > irq_domain_remove in grgpio_remove > drivers/gpio/gpio-grgpio.c, 449: > _raw_spin_lock_irqsave in grgpio_remove > > mutex_lock() can sleep at runtime. > > To fix these bugs, gpiochip_remove() and irq_domain_remove() are called > without holding the spinlock. > > These bugs are found by a static analysis tool STCheck written by myself. > > Signed-off-by: Jia-Ju Bai > --- > drivers/gpio/gpio-grgpio.c | 5 ++++- > sound/soc/sti/uniperif_player.c | 3 ++- > 2 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c > index 08234e64993a..60a2871c5ba7 100644 > --- a/drivers/gpio/gpio-grgpio.c > +++ b/drivers/gpio/gpio-grgpio.c > @@ -448,13 +448,16 @@ static int grgpio_remove(struct platform_device *of= dev) > } > } > > + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); > + > gpiochip_remove(&priv->gc); > > if (priv->domain) > irq_domain_remove(priv->domain); > > out: > - spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); > + if (ret) > + spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); In general there is no need for locking in remove() callbacks. I guess you can safely remove the spinlock here all together. > > return ret; > } > diff --git a/sound/soc/sti/uniperif_player.c b/sound/soc/sti/uniperif_pla= yer.c > index 48ea915b24ba..62244e207679 100644 > --- a/sound/soc/sti/uniperif_player.c > +++ b/sound/soc/sti/uniperif_player.c > @@ -601,13 +601,14 @@ static int uni_player_ctl_iec958_put(struct snd_kco= ntrol *kcontrol, > mutex_unlock(&player->ctrl_lock); > > spin_lock_irqsave(&player->irq_lock, flags); > + spin_unlock_irqrestore(&player->irq_lock, flags); Yeah I can tell this was generated automatically - what does this line is expected to achieve? Bart > + > if (player->substream && player->substream->runtime) > uni_player_set_channel_status(player, > player->substream->runtime)= ; > else > uni_player_set_channel_status(player, NULL); > > - spin_unlock_irqrestore(&player->irq_lock, flags); > return 0; > } > > -- > 2.17.1 >