Received: by 10.192.165.156 with SMTP id m28csp229126imm; Tue, 10 Apr 2018 20:27:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+GDxW3PnpD8BCbUfHBHdoa85oRB3uGnhVFjlcY/u3LZiuhEkR3NkNas6sKkGWk/EOYTMSW X-Received: by 10.98.108.69 with SMTP id h66mr2499636pfc.43.1523417250443; Tue, 10 Apr 2018 20:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523417250; cv=none; d=google.com; s=arc-20160816; b=eK/Io3TkbPZwIrjWDqG8jpqI97L5sdNrXN3Lfo4kXDpSzPxWSnCZqEapR8TX1l694+ WElBBidqkcBwITWRLJQRr97m1P7b7cf1/v5PpWUKXfbzqBT+yUm07SiLW88iuWg+gBc/ 4jBkcdARf59J4lTqtXIXF7VT/+t8aLMm0v7q79gglVTefnyIyeMB/k41iFiGiHPNKBYJ ssvwfb47rGpbc8DE1POqi3X+aFALMrnL8eUFvRRzXBGsTzBIKbjUPSp7PMsTSZZ0zwTd 4GtkUcwWuQFLPilod4Q7ZkP82ds5kwGZTE1u3UuLxnGzWgL9rOiI2eusA+zNo5xKIcIg Ct+g== 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:arc-authentication-results; bh=OlEyWKeUp0Z3yw3y1C/AG1y2ebTbyMSlNaVNCamrQJQ=; b=v5aphSa1u+1d4hwWSKqYUIPE+5TYnoe8336g9elof4zfS0x1CYuzeJgtHKhnyniXvw +ega0dZV1t+Ss9Y/cC02EwFHiw9Z6CM2dUUbNfUQ4+eIugxkBB3eZHMRPZVa+EpOChDZ sVf1/H1j+ZrGpi2G7YDj/8meaSI21QrdaN//gRkhPT1VlIiKlM3sUE9Q/jOcvwiSW1ie VDjtYQegVIMmhgXvAzlz4kT42mhVyWT1hws6gI8v0mYzkHqDdW0spRtV+tY/LWHLGHWz +xfZtnt2MP5+JQeMHvz1oJz9WCTSS3/9rM3WnwW2Ve4rAOdQAcsZbYi5WP4TMN+HAlr7 fB2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dZG3uxdy; 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 u10-v6si226337plr.123.2018.04.10.20.26.53; Tue, 10 Apr 2018 20:27:30 -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=dZG3uxdy; 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 S1752745AbeDKDX5 (ORCPT + 99 others); Tue, 10 Apr 2018 23:23:57 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35322 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752334AbeDKDX4 (ORCPT ); Tue, 10 Apr 2018 23:23:56 -0400 Received: by mail-pf0-f194.google.com with SMTP id u86so274532pfd.2; Tue, 10 Apr 2018 20:23:55 -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=OlEyWKeUp0Z3yw3y1C/AG1y2ebTbyMSlNaVNCamrQJQ=; b=dZG3uxdydKls0vgoSO5V1H9rwJuYJgpiHenBXc/3TkyG7vPVaimpKaziJIKjCHqeLe 0dLk7hlPxOh/ka6XdjXE0s9wDrbhZGuyEC/DkAyidkpk98zw0bEu7DNHxnDjXs44NXOV vtMRCiys/04tVCdpSRNHc1clfzDhPQVbr+LFwvRPiCjlpAtkDN7pEY3uLyKUpMHqvuMK 41V30rOhPN8XSjMxpNJAntq0CddXjev0V9flAl8qPr96N15+1izJSxiqMzoSHbL9kQxz FGxU8RwFbhyHHJOfJtT1rcsQGKaC4P3s477j6MnwaB2DNfHBWAYyt6ptrPD2tzh4YEcQ WVuA== 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=OlEyWKeUp0Z3yw3y1C/AG1y2ebTbyMSlNaVNCamrQJQ=; b=fGKTkrcfDV0m3jliPiOwst7iViaDSlD91Ap5WJzXqyNxuA15xvw/whKSrTaT7eZOrZ VoR2B4QTXgxJgIFvJBYC7BONu2/Y1oqyvbVZe1I4JN8yWdo7WaceLlK6StCnvjT1Uib6 9AAhaxiPl+hSBzn9ieEcvhv7ahzGe6U/r0yV5PgGUAgonV5fFi3XIZKboWj4+ydxrxhW jP2Gy27x2hfdhl8lHJL/O95xQxuAW4fjwrL7mm9kBjqIJZI4JXxtaI3H/7j0WyghJ622 Xl2mjM16559Lc3t1p2QK+RTtdSZ8FlsdlzHL4ADm+2XiWRAFQD/24fA+scXu3NHDqZc+ CkuQ== X-Gm-Message-State: ALQs6tBw9H9eHOuekR+6FW/BsyVOahX0QkKyidjqYFFV6m1Xu1xn+CjL tgDzW++cDhAJ4jLmWQGGgn0= X-Received: by 10.99.167.6 with SMTP id d6mr2063010pgf.287.1523417035396; Tue, 10 Apr 2018 20:23:55 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:1:4413:edc8:c1dd:b0a8:461d]) by smtp.gmail.com with ESMTPSA id o18sm217823pgd.59.2018.04.10.20.23.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Apr 2018 20:23:54 -0700 (PDT) From: Jia-Ju Bai To: mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH 1/3] media: dvb-usb: Replace GFP_ATOMIC with GFP_KERNEL in usb_allocate_stream_buffers Date: Wed, 11 Apr 2018 11:23:49 +0800 Message-Id: <1523417029-3069-1-git-send-email-baijiaju1990@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org usb_allocate_stream_buffers() is never called in atomic context. The call chains ending up at usb_allocate_stream_buffers() are: [1] usb_allocate_stream_buffers() <- usb_bulk_urb_init() <- usb_urb_init() <- dvb_usb_adapter_stream_init() <- dvb_usb_adapter_init <- dvb_usb_init() <- dvb_usb_device_init() <- xxx_probe() [2] usb_allocate_stream_buffers() <- usb_isoc_urb_init() <- usb_urb_init() <- dvb_usb_adapter_stream_init() <- dvb_usb_adapter_init <- dvb_usb_init() <- dvb_usb_device_init() <- xxx_probe() xxx_probe including ttusb2_probe, vp7045_usb_probe, a800_probe, and so on. These xxx_probe() functions are set as ".probe" in struct usb_driver. And these functions are not called in atomic context. Despite never getting called from atomic context, usb_allocate_stream_buffers() calls usb_alloc_coherent() with GFP_ATOMIC, which does not sleep for allocation. GFP_ATOMIC is not necessary and can be replaced with GFP_KERNEL, which can sleep and improve the possibility of sucessful allocation. This is found by a static analysis tool named DCNS written by myself. And I also manually check it. Signed-off-by: Jia-Ju Bai --- drivers/media/usb/dvb-usb/usb-urb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/dvb-usb/usb-urb.c b/drivers/media/usb/dvb-usb/usb-urb.c index 8917360..96be721 100644 --- a/drivers/media/usb/dvb-usb/usb-urb.c +++ b/drivers/media/usb/dvb-usb/usb-urb.c @@ -117,7 +117,7 @@ static int usb_allocate_stream_buffers(struct usb_data_stream *stream, int num, for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) { deb_mem("allocating buffer %d\n",stream->buf_num); if (( stream->buf_list[stream->buf_num] = - usb_alloc_coherent(stream->udev, size, GFP_ATOMIC, + usb_alloc_coherent(stream->udev, size, GFP_KERNEL, &stream->dma_addr[stream->buf_num]) ) == NULL) { deb_mem("not enough memory for urb-buffer allocation.\n"); usb_free_stream_buffers(stream); -- 1.9.1