From patchwork Tue Apr 21 15:42:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 463371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D597314011D for ; Wed, 22 Apr 2015 01:47:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=q16aQjDr; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932993AbbDUPna (ORCPT ); Tue, 21 Apr 2015 11:43:30 -0400 Received: from mail-lb0-f173.google.com ([209.85.217.173]:34395 "EHLO mail-lb0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755875AbbDUPnS (ORCPT ); Tue, 21 Apr 2015 11:43:18 -0400 Received: by lbcga7 with SMTP id ga7so159090114lbc.1; Tue, 21 Apr 2015 08:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=C5W5pv+h2caPio/7rO4gSASlmlyK8JlmPwfAY9/sCmQ=; b=q16aQjDr3ZNycdrWssPc46s06YgRsBRhWpR9sxrvFco0xvi3cPrmki2Gh8NuPibjBF rXcll8fvCISoYPYja+IEM8NjnmzC4d9vVcycdX8ET5mZqooIBzuXqpdK7dWLX9PUt2ls Tg6gB3+dtAfs+zfo0alxTF7oGZmsw6kWRsyKqd05uUS1fIcBckOrVgKQwx4fzDln9YXr MswUrbPKH+rRGYhKE7J7qGHeh9omjhL1wQiwghGbobYWFzw9DU4NN/Z3SvUDX3eBkXTR /NIwspEATYTyATcTE/WjNJia04m0CBR5Yls6ecBnDgw34s7xZpDmz8rYWFxxOeQOeOXX rZ1A== X-Received: by 10.112.125.193 with SMTP id ms1mr20919435lbb.31.1429630997163; Tue, 21 Apr 2015 08:43:17 -0700 (PDT) Received: from xi.terra (c193-14-96-226.cust.tele2.se. [193.14.96.226]) by mx.google.com with ESMTPSA id ao5sm475532lac.48.2015.04.21.08.43.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Apr 2015 08:43:10 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.84) (envelope-from ) id 1YkaKM-00074Z-A1; Tue, 21 Apr 2015 17:43:10 +0200 From: Johan Hovold To: Linus Walleij Cc: Alexandre Courbot , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 10/23] gpio: sysfs: release irq after class-device deregistration Date: Tue, 21 Apr 2015 17:42:18 +0200 Message-Id: <1429630951-27082-11-git-send-email-johan@kernel.org> X-Mailer: git-send-email 2.0.5 In-Reply-To: <1429630951-27082-1-git-send-email-johan@kernel.org> References: <1429630951-27082-1-git-send-email-johan@kernel.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Make sure to release any irq only after the class device has been deregistered. This avoids a race between gpiod_unexport and edge_store, where an irq could be allocated just before the gpio class device is deregistered without relying on FLAG_EXPORT and the global sysfs lock. Note that there is no need to hold the sysfs lock when releasing the irq after the class device is gone as kernfs will prevent further attribute operations. Signed-off-by: Johan Hovold --- drivers/gpio/gpiolib-sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 9d9f1f1a2417..d896b6fa7fe8 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -680,7 +680,6 @@ void gpiod_unexport(struct gpio_desc *desc) dev = class_find_device(&gpio_class, NULL, desc, match_export); if (dev) { - gpio_setup_irq(desc, dev, 0); clear_bit(FLAG_SYSFS_DIR, &desc->flags); clear_bit(FLAG_EXPORT, &desc->flags); } else @@ -691,6 +690,11 @@ void gpiod_unexport(struct gpio_desc *desc) if (dev) { device_unregister(dev); + /* + * Release irq after deregistration to prevent race with + * edge_store. + */ + gpio_setup_irq(desc, dev, 0); put_device(dev); }