Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2690486ybl; Thu, 29 Aug 2019 11:31:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhXe8P9d+jKQYe2URd2J1F+B7hK2WsUesgStObew+x8eg34lMSwjtiMfJXogiotTo5WGgE X-Received: by 2002:a17:90a:feb:: with SMTP id 98mr10792711pjz.55.1567103494639; Thu, 29 Aug 2019 11:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103494; cv=none; d=google.com; s=arc-20160816; b=oyLGomwxSjf2cjUcYyThZDrad2ntfdkwt+Px4PaMKes/ucVxOgbxnjtZi3pFKt8kpx i0l5IsYs5UFRM7JlQMtu9TE4SBJDXf1xn7i3Zk7IBav0ewdu9P3l4z9KBthG5Tr/2kP1 H8WS37P5uf0d9jVPc/DYWXc+18q7M3SjuRH6SWbWWY2cxlLKmLXHIck0SuLJbWRqemj3 ampoSxq03OgF/B8/GJisuoHIrvogVwwyV1ax+7ED5wIkJihJ2GuCR9+nDh3Iz2h1FR8P TfUHOQpfFTnw9Z+D/zgk89D9szwbO5IlqY8/V00L9aPj26X2Aqmk7k2B7Q9AffogjT9J vK4g== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KU6scymSOJqpObRyvYV9dMO+0QIEH2zvOxz2PwLA7d4=; b=iMm7gVyWXwmatCK12yqvWC4twzFmwbhOXEtFxbKKONWB/IH5Ar6BB/eB7lyiX+LHDq hoCGhUCS714QtRlvEYt4FwTCmzi6OL9oHB6Qlg1U/I/nWYGtRsjeqtLHrrR9xtFdlm+P k+UxcOAKWXmO6cTPCGBSIwm/5AjglJHZJbyea3PQk5UoRObA7/EsveXnrsQ2iYwtVwwz VarJYcTs02KBk0zL7Qkw0T0RJ4mHYTbUSk6u1w/jGoajRPAbDAZAKqBib3bYYTLdtJGv kNWQIXb/38wGPrmzMofcAcLk2C5IVlDT/IRnINyn7belKSzK/BCObHIUrbxCRRr10LJm zXWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ySz//tuw"; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 207si3311896pfy.222.2019.08.29.11.31.19; Thu, 29 Aug 2019 11:31:34 -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=@kernel.org header.s=default header.b="ySz//tuw"; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729123AbfH2SPC (ORCPT + 99 others); Thu, 29 Aug 2019 14:15:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:56608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729082AbfH2SO6 (ORCPT ); Thu, 29 Aug 2019 14:14:58 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E534823405; Thu, 29 Aug 2019 18:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102497; bh=cIBmie2SDl6fWDIBpvZGPqToFNOLY9z40Csdp2T6Pt0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ySz//tuwyBcxQVLhVK74jU6TYVKKyjYKBBAAYi7OxLYyA0r8eM/sDnEqoH5jhZgpG 0Y1DPR/b8UbQKH6dp7s5DYeeX+stdjH/+C6S5AJuPW9zpybqM2xYhCu/BksKBw/jsc Rnp3GR7pa0aWL0klT1w0k65ykK+wg9819r6KRDeY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Benjamin Tissoires , Jiri Kosina , Sasha Levin , linux-input@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 50/76] HID: cp2112: prevent sleeping function called from invalid context Date: Thu, 29 Aug 2019 14:12:45 -0400 Message-Id: <20190829181311.7562-50-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Tissoires [ Upstream commit 2d05dba2b25ecb0f8fc3a0b4eb2232da6454a47b ] When calling request_threaded_irq() with a CP2112, the function cp2112_gpio_irq_startup() is called in a IRQ context. Therefore we can not sleep, and we can not call cp2112_gpio_direction_input() there. Move the call to cp2112_gpio_direction_input() earlier to have a working driver. Signed-off-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-cp2112.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c index 8bbe3d0cbe5d9..8fd44407a0df7 100644 --- a/drivers/hid/hid-cp2112.c +++ b/drivers/hid/hid-cp2112.c @@ -1152,8 +1152,6 @@ static unsigned int cp2112_gpio_irq_startup(struct irq_data *d) INIT_DELAYED_WORK(&dev->gpio_poll_worker, cp2112_gpio_poll_callback); - cp2112_gpio_direction_input(gc, d->hwirq); - if (!dev->gpio_poll) { dev->gpio_poll = true; schedule_delayed_work(&dev->gpio_poll_worker, 0); @@ -1201,6 +1199,12 @@ static int __maybe_unused cp2112_allocate_irq(struct cp2112_device *dev, return PTR_ERR(dev->desc[pin]); } + ret = cp2112_gpio_direction_input(&dev->gc, pin); + if (ret < 0) { + dev_err(dev->gc.parent, "Failed to set GPIO to input dir\n"); + goto err_desc; + } + ret = gpiochip_lock_as_irq(&dev->gc, pin); if (ret) { dev_err(dev->gc.parent, "Failed to lock GPIO as interrupt\n"); -- 2.20.1