Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1921435ybl; Thu, 19 Dec 2019 05:17:36 -0800 (PST) X-Google-Smtp-Source: APXvYqwQcUqZMadrVMsRY4SJD8UJhjhGQH9AX6Ye6lxGy8SgKu17BVPD6mA0gVjzAuX92vGzLijY X-Received: by 2002:a9d:3b23:: with SMTP id z32mr8309240otb.159.1576761456411; Thu, 19 Dec 2019 05:17:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576761456; cv=none; d=google.com; s=arc-20160816; b=jofGR3mQBaCwNxl3UaFXWoi9YqxrvdDOFdtvn39ubuMGrZdMEcpl/bCX35suU/U41y Kmv0/nJGGCqUavqEthDSd1coPCkwuwwe2L/c51lPbW+EJQhQNwEkT9sba/N38ZUHogtR Lz5Qaedc/mBabRU/LncNTdJSVhrKyENaLenODE0787JfoOHp4+j0HU7wHHFfx/99n2fM GYZ7vhmYksKb4m9gIyAE5Frn22tsz7Byow3+7DgIutGG2Xw+NVpCgciAdVar2HtkrNVZ 5NRYmWFB0nDGncSk834FTQV9X7xcDG10WpiPQNtaij+HdS6+Y0pZB+s0En9piqIcqob3 CESQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=EVebG2mxl2pFbRKmtKvplGDYfctGq6ipwixunLpsjMo=; b=BbNQUvn8ZQw/RQybR57F907GC7YWDOGlWTVjK86NEvxut0hLc8Sa6wXv10taznBKdC FT/RouTaLj1Fq9HCj6TDEBs1VMSbPegzpempxcc5TMTq2ISfAG1BcjiQMLhiOwZm0RKa ZboVP4nIDb+7XhjUL9azM94/JVvqtZU5AKyR2GdMg1LvYTJ5ltUb1gsTOwvoGJEKCc6m Z6hhoQ6iiKwwl2oSAoQnuJlJYoR0fkrwjRooxJCqxpplzO2cebQRgatImBvxcUc0tKPF BlHnar/uj/97YK21gU3CrZfg2yo7eWOD2MC7AKg5jKEGSeHseh6/6dRkPTwn8fkSGLOn DH/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i1fphoqZ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s11si3477012otd.123.2019.12.19.05.17.17; Thu, 19 Dec 2019 05:17:36 -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=@gmail.com header.s=20161025 header.b=i1fphoqZ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727006AbfLSNP6 (ORCPT + 99 others); Thu, 19 Dec 2019 08:15:58 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:54589 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726961AbfLSNP6 (ORCPT ); Thu, 19 Dec 2019 08:15:58 -0500 Received: by mail-pj1-f65.google.com with SMTP id ep17so2506308pjb.4; Thu, 19 Dec 2019 05:15:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=EVebG2mxl2pFbRKmtKvplGDYfctGq6ipwixunLpsjMo=; b=i1fphoqZCkW4TfNecoJIQUs7pOzb64NjVceblA4niuUzc3lN9qr7fCDirz8Qtly2pU 7mats1aY7LeNSFoqLpabz+qUtMSf5S4LBHNu2d0EAdu/Pxy/7ufPxtANYZbYsF/SdZ5V iq7rO/HUELq6aJ82b3X35Pov1K1hzLY0ATZbM8fSMFF4dkn1/2k6AA+EjFwBT1BpkBlS I6nDHwepj2UKBWwMNO33djHVHeNHUf7fXOKf3RZtyhcZHHjaVBaXDS50+g0845Km4l50 VFcVZRytMHgnq1qyS7JfeySpMOjUewwcXZJNmoS4ORL2Uk+A6oq3sho7e8ODrMqrCrLj ew2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EVebG2mxl2pFbRKmtKvplGDYfctGq6ipwixunLpsjMo=; b=IrzQoKjFOiXxfPs64PyFMqAVGZtj/4IoNLMoe3O2faLxaEaVJPTdEqhKhRySCn4wiQ DL7QL7Sro8Viu/BQZa6jQSTLo06r5fkgiD1pmiFHsXpRVyfPny38liyT8bKM+SY4R1FT 600Usz+1kHDbcHQmLufENtvNlLXlEFC42mfRH/5Zmv8LYqMHHKRzwm6s4XvcG1kTTgUL MPscaG+Xpmxh+/cbEOXgeXmkYvgHO1KT2liaDkilKjlbBGabt7XT+qDfWl2d5RQXoibH h0Q5SSguVbmH3k2k7c0X2rrjDnAPpLXkYXmG+OVseThTbQI7gs5VBq/W6cMI8BZ1LW9c RT0w== X-Gm-Message-State: APjAAAVbi+6KXbMwUW2R5IPjJr9xhP7CkTDdBqxXH5hQcpqwCSf4wZQG WnqStRGa6f3/qX4wnGmKwgM= X-Received: by 2002:a17:90a:d145:: with SMTP id t5mr9755894pjw.57.1576761357616; Thu, 19 Dec 2019 05:15:57 -0800 (PST) Received: from oslab.tsinghua.edu.cn ([166.111.139.172]) by smtp.gmail.com with ESMTPSA id d22sm8079229pfo.187.2019.12.19.05.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 05:15:56 -0800 (PST) From: Jia-Ju Bai To: linus.walleij@linaro.org, bgolaszewski@baylibre.com Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH 1/2 v2] gpio: gpio-grgpio: fix possible sleep-in-atomic-context bugs in grgpio_remove() Date: Thu, 19 Dec 2019 21:14:59 +0800 Message-Id: <20191219131459.18640-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, the lock is dropped in grgpio_remove(), because there is no need for locking in remove() callbacks. These bugs are found by a static analysis tool STCheck written by myself. Signed-off-by: Jia-Ju Bai --- v2: * Drop the lock instead of moving the calls to lock functions. Thank Bartosz for good advice. --- drivers/gpio/gpio-grgpio.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c index 08234e64993a..a49f0711ca94 100644 --- a/drivers/gpio/gpio-grgpio.c +++ b/drivers/gpio/gpio-grgpio.c @@ -437,8 +437,6 @@ static int grgpio_remove(struct platform_device *ofdev) int i; int ret = 0; - spin_lock_irqsave(&priv->gc.bgpio_lock, flags); - if (priv->domain) { for (i = 0; i < GRGPIO_MAX_NGPIO; i++) { if (priv->uirqs[i].refcnt != 0) { @@ -454,8 +452,6 @@ static int grgpio_remove(struct platform_device *ofdev) irq_domain_remove(priv->domain); out: - spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags); - return ret; } -- 2.17.1