From patchwork Wed Jun 10 14:34:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 482696 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 8E980140295 for ; Thu, 11 Jun 2015 00:34:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965004AbbFJOeE (ORCPT ); Wed, 10 Jun 2015 10:34:04 -0400 Received: from mail-wg0-f46.google.com ([74.125.82.46]:33403 "EHLO mail-wg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964870AbbFJOeC (ORCPT ); Wed, 10 Jun 2015 10:34:02 -0400 Received: by wgez8 with SMTP id z8so37343665wge.0 for ; Wed, 10 Jun 2015 07:34:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=hyFc5rfk1EAZcfhAU5xK0BveOGsSmOockOA+IogyOhs=; b=bjiEZHdL7BCPR55NDW86K8DCgmjJVd2Sh3AeVDR1dsgEjSmzPUevMnV8K/CFaQcPnk Mf3Lvzal4KUTHTZqXDjWLLDQpJezKXr+S4wGMkoT6YRKICrhfE4VO23tcdUoVaMghcKx 1Km6Qvk45ZiJO1xnFRpfBbWHlQ3KgxVb4gyt0LlZPbeqelaSzBbEhiEqFiflpOL3OGJi GX+QIhqLb5C7TOUeKsYbmTWX12aihbEfeI8u1ufzC7OlVQiJ+tJxT69KHr/c0yLvmhn/ x1Sip6dlbdOvTWK1moTDOTld8Os9qVFjyASHFCFQDEtFBvogtFO8+jJxUV3vMNerrNJ/ c6Xw== X-Gm-Message-State: ALoCoQklVCZMXmYBBNzn3nK/wmvKVnNKkD/51LhJ9u+vXALjre3v8ywp6BlB5bHBlioJQ3adoMoZ X-Received: by 10.180.73.230 with SMTP id o6mr9242293wiv.11.1433946841679; Wed, 10 Jun 2015 07:34:01 -0700 (PDT) Received: from localhost.localdomain (cag06-6-78-235-100-105.fbx.proxad.net. [78.235.100.105]) by mx.google.com with ESMTPSA id u9sm14862018wju.44.2015.06.10.07.33.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jun 2015 07:34:00 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot Cc: linux-gpio , LKML , Patrick Titiano , Benoit Cousson , Bartosz Golaszewski Subject: [PATCH] gpiolib: unexport requested gpios on gpiochip removal Date: Wed, 10 Jun 2015 16:34:21 +0200 Message-Id: <1433946861-22371-1-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org When a GPIO expander device is removed - e.g. via i2c-adapter new_device/delete_device interface - with some GPIOs still requested, gpiochip_remove() function will emit a warning but remove the chip anyway. If we then reinstantiate this device and try to export any of the GPIOs still requested on gpiochip deletion the following warning will be emitted: WARNING: CPU: 0 PID: 90 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x58/0x78() sysfs: cannot create duplicate filename '/class/gpio/gpio504' Modules linked in: gpio_pca953x ipv6 CPU: 0 PID: 90 Comm: sh Not tainted 4.0.0 #1 Hardware name: Generic AM33XX (Flattened Device Tree) [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0x84/0x9c) [] (dump_stack) from [] (warn_slowpath_common+0x7c/0xb8) [] (warn_slowpath_common) from [] (warn_slowpath_fmt+0x30/0x40) [] (warn_slowpath_fmt) from [] (sysfs_warn_dup+0x58/0x78) [] (sysfs_warn_dup) from [] (sysfs_do_create_link_sd.isra.2+0xb0/0xb8) [] (sysfs_do_create_link_sd.isra.2) from [] (device_add+0x1e4/0x510) [] (device_add) from [] (device_create_groups_vargs+0x9c/0xc0) [] (device_create_groups_vargs) from [] (device_create_with_groups+0x24/0x2c) [] (device_create_with_groups) from [] (gpiod_export+0xf8/0x224) [] (gpiod_export) from [] (export_store+0x50/0xd0) [] (export_store) from [] (class_attr_store+0x18/0x24) [] (class_attr_store) from [] (sysfs_kf_write+0x4c/0x50) [] (sysfs_kf_write) from [] (kernfs_fop_write+0xbc/0x1a4) [] (kernfs_fop_write) from [] (vfs_write+0xa4/0x1b0) [] (vfs_write) from [] (SyS_write+0x40/0x94) [] (SyS_write) from [] (ret_fast_syscall+0x0/0x4c) sysfs_do_create_link_sd() fails due to dangling links in /sys/class/gpio rendering these GPIOs unusable until reboot. Instead of warning the user, just silently unexport all requested GPIOs. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6bc612b..74a5e45 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -342,7 +342,7 @@ void gpiochip_remove(struct gpio_chip *chip) spin_lock_irqsave(&gpio_lock, flags); for (id = 0; id < chip->ngpio; id++) { if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) - dev_crit(chip->dev, "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); + gpiod_unexport(&chip->desc[id]); } for (id = 0; id < chip->ngpio; id++) chip->desc[id].chip = NULL;