Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1490618imm; Fri, 14 Sep 2018 20:05:14 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZbfa7gywRUYPEEBAA53uKU94Y1rL3hcwPa+GGjvqV2AA8f66DCDfF+edkLDgdmy5GteaQK X-Received: by 2002:a62:1456:: with SMTP id 83-v6mr15085238pfu.50.1536980714489; Fri, 14 Sep 2018 20:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536980714; cv=none; d=google.com; s=arc-20160816; b=NCJIolk5rtwYtVDG4EXdKKIjVtSzIjcmAZKPazq9eitGveM8Q0eP0CLSelZUBtx/vM uJe5hwGWUHLmE2CY9q8TPnPiADQUPQ2s8a8KJelPmB1cp7ZNguHMY2SzHRMwwFN000r6 7NdoggI9oHg5VoBytRiuZcrFbo3Th+cukirJAQOdNoJt7aXeI+2ghJl52hzijfyzIK6N OBlVnJDjlJeydDudf6rsiKqr5WBnlKkDKRA+HB82ug443vVXArnWT33pv3QjzYwpfzOm 7tfJSB7xZq1MUArKKP3taD+GYo/L+yE0dNOC19HYsTWGGk4AUIjDe9tIRu9fD99Lnz/W ekgg== 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=8ziJA4qx94zca7h+UBhv0tAT4GL60Ekts6sL7jHf+Ns=; b=BFr9PfwyJ1gwkkzgKpcWq3DwMrunUe6SyAn2D0PSbxGiaOoRWE1G2dcWD5PVfgb5sx MFtAR/yDu8OEIHPPJeU3wzfQYBXPnvX47oLS9gdoIuvHTlePMGJb8qtnzzdq+wXQtid6 evSWTs7hkzU35pqYYpjJ/LEtqtrmt6EpeETe3yVOpUIEBtMdF5VlwP0+7b6r/GzFf7Ur g1VZI2hjM9JhcbZB0actd5yCMhYpT2fYUuLVulqjLzTOhhQzfpXjXXEVEhSYhI8HglI5 wrplHyVBTcA/S7kz+LwlScvP4SX8yBqxHZTtCGc47CMVKZSZvg9v2UXxvhBoId0mVvcZ 9o9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="qZG7QAn/"; 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 m141-v6si9002424pfd.310.2018.09.14.20.04.58; Fri, 14 Sep 2018 20:05:14 -0700 (PDT) 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="qZG7QAn/"; 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 S1727716AbeIOIWL (ORCPT + 99 others); Sat, 15 Sep 2018 04:22:11 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44409 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbeIOIWL (ORCPT ); Sat, 15 Sep 2018 04:22:11 -0400 Received: by mail-pl1-f196.google.com with SMTP id ba4-v6so4985513plb.11; Fri, 14 Sep 2018 20:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=8ziJA4qx94zca7h+UBhv0tAT4GL60Ekts6sL7jHf+Ns=; b=qZG7QAn/2w/ZlUAhqwzkOYptgA39Ut/x1OdsMg1xxGGbg8170VSKPpb7ov8uBwcFa+ hVsNiMLUg1zwqkMeIMq31cjgidXq0kF7LuaUn3aeS8wS0jFuk6St+vuwRKtKGIffimTf gJPH2wMLeLoONIr/MVauFfpYckgL6tQ6cTlVA3q3lzwpa3WUvSCntKWd02t6bBVXmagH bGibjtxSzAr1JxgmknAenMrNjARTu6luu+AnTNxDbj5DB7Gl7zBV760tlmZ+GHHnng8w lt5pW97bgeWtRqxvyfFPfOxI/uJSiBRQd8orqjKQY9VMEmEd9spfTRJeAnX+FF3wO1pD k0Og== 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=8ziJA4qx94zca7h+UBhv0tAT4GL60Ekts6sL7jHf+Ns=; b=X3Kz28wEPREy0JmITWxPy1NmUS6LwuChh8F4iuWEtrF93N1UikL/7qXyww1atB2UwB pxisdL3v8/hfC+IYQwG+Kd0AeEDyoaT7GQjVA8G7l58p2CwL30CrPryuFgVq6LZgFqNy VoCwY+8J06BUtT88HPSZQm5K6caZX+RXVKRPC9AX1po1cM/qEals5DnRxJ3N8TWUxNNn 4qSvOrbF8mlNzVBIEeBOx96MuOA2myF5dh1AKgGKW27T00VmohADJYsvoZ3LF/90aY4q hRCga/HnuVxN1Wc8QZFC5fseRVBTeflwYbZpSSv12H+vqblaaXGeWt8pXtetutzWzZSC G7gA== X-Gm-Message-State: APzg51DqhBbmUiqEgE2JJ3XloqhvziGfmPrtrHyNGssH+qiviysO70+z eWA85YXbA3MKfgJ/wB87zeE= X-Received: by 2002:a17:902:4401:: with SMTP id k1-v6mr14279713pld.97.1536980691861; Fri, 14 Sep 2018 20:04:51 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:947c:62c0:a59c:7c99]) by smtp.gmail.com with ESMTPSA id j191-v6sm12779101pfc.136.2018.09.14.20.04.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 20:04:51 -0700 (PDT) From: Jia-Ju Bai To: balbi@kernel.org, gregkh@linuxfoundation.org, nicolas.ferre@microchip.com, leoyang.li@nxp.com, robert.jarzmik@free.fr Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] usb: gadget: udc: fotg210-udc: Fix a sleep-in-atomic-context bug in fotg210_get_status() Date: Sat, 15 Sep 2018 11:04:40 +0800 Message-Id: <20180915030440.17646-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The driver may sleep in an interrupt handler. The function call path (from bottom to top) in Linux-4.17 is: [FUNC] fotg210_ep_queue(GFP_KERNEL) drivers/usb/gadget/udc/fotg210-udc.c, 744: fotg210_ep_queue in fotg210_get_status drivers/usb/gadget/udc/fotg210-udc.c, 768: fotg210_get_status in fotg210_setup_packet drivers/usb/gadget/udc/fotg210-udc.c, 949: fotg210_setup_packet in fotg210_irq (interrupt handler) To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC. If possible, spin_unlock() and spin_lock() around fotg210_ep_queue() can be also removed. This bug is found by my static analysis tool DSAC. Signed-off-by: Jia-Ju Bai --- drivers/usb/gadget/udc/fotg210-udc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c index 53a48f561458..c51510803d1f 100644 --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c @@ -741,7 +741,7 @@ static void fotg210_get_status(struct fotg210_udc *fotg210, fotg210->ep0_req->length = 2; spin_unlock(&fotg210->lock); - fotg210_ep_queue(fotg210->gadget.ep0, fotg210->ep0_req, GFP_KERNEL); + fotg210_ep_queue(fotg210->gadget.ep0, fotg210->ep0_req, GFP_ATOMIC); spin_lock(&fotg210->lock); } -- 2.17.0