From patchwork Thu Nov 12 18:26:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 7604821 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CBF29BF90C for ; Thu, 12 Nov 2015 18:27:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EE5802081B for ; Thu, 12 Nov 2015 18:27:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 265C220739 for ; Thu, 12 Nov 2015 18:27:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751907AbbKLS1C (ORCPT ); Thu, 12 Nov 2015 13:27:02 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:35556 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751769AbbKLS1A (ORCPT ); Thu, 12 Nov 2015 13:27:00 -0500 Received: by pasz6 with SMTP id z6so74796075pas.2; Thu, 12 Nov 2015 10:27:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=aQDqdV1iI/kf0+iSeiqfFDQkSdJdzgSmMXrs0w2JIEo=; b=BHmrrexBxr1wIaHGURoRPGmabUbHRkOqjjCfmrcP6C8lhIyTF7si6ZPYOhgnfUxpD4 0RO3vVjtbomNIi7JyiCLZwe6k/W/Xb2q8rLudh3O0w3RId7oRAlyFNkyjYw5+dbBQqvH Bl9ISzXkuigNd+FaaovwM5LtftN2s1YIBGSUQU0FJfqh+xc5k7i69ifxNjmiT0oyRd+2 ZRwv8KRNBgXkEhLQB9h2XsQkT95dRci+4enYJXtDVHapa0t3sk+ytKM7flGcfkyMcP4s ZB+dqxfur1znG8Di5Yn1Tr2rrylKko2Ph+Kt6sZ0bPrZZ3TA+LU5WUvyz+uWe/JBMWWH +ndQ== X-Received: by 10.68.114.36 with SMTP id jd4mr25194759pbb.135.1447352820280; Thu, 12 Nov 2015 10:27:00 -0800 (PST) Received: from dtor-ws ([2620:0:1000:1301:c14c:e484:1f9a:5a74]) by smtp.gmail.com with ESMTPSA id eg5sm16034289pac.30.2015.11.12.10.26.59 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 12 Nov 2015 10:26:59 -0800 (PST) Date: Thu, 12 Nov 2015 10:26:57 -0800 From: Dmitry Torokhov To: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman , Tony Lindgren , Grygorii Strashko , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] PM / wakeirq: check that wake IRQ is valid before accepting it Message-ID: <20151112182657.GA19785@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check that IRQ number passed to dev_pm_set_wake_irq and dev_pm_set_dedicated_wake_irq is valid (not negative) before accepting it. Signed-off-by: Dmitry Torokhov --- My recent change to i2c core introduced a code path that led to calling dev_pm_set_wake_irq(&client->dev, -ENOENT), which succeeded but obviously did the wrong thing. Checking the IRQ and bailing out early would have helped noticing this issue earlier. drivers/base/power/wakeirq.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/base/power/wakeirq.c b/drivers/base/power/wakeirq.c index eb6e674..0d77cd6 100644 --- a/drivers/base/power/wakeirq.c +++ b/drivers/base/power/wakeirq.c @@ -68,6 +68,9 @@ int dev_pm_set_wake_irq(struct device *dev, int irq) struct wake_irq *wirq; int err; + if (irq < 0) + return -EINVAL; + wirq = kzalloc(sizeof(*wirq), GFP_KERNEL); if (!wirq) return -ENOMEM; @@ -167,6 +170,9 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq) struct wake_irq *wirq; int err; + if (irq < 0) + return -EINVAL; + wirq = kzalloc(sizeof(*wirq), GFP_KERNEL); if (!wirq) return -ENOMEM;