From patchwork Mon Jan 26 18:05:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 432970 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 3A1F91401DD for ; Tue, 27 Jan 2015 05:06:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757137AbbAZSGS (ORCPT ); Mon, 26 Jan 2015 13:06:18 -0500 Received: from mail-lb0-f178.google.com ([209.85.217.178]:54792 "EHLO mail-lb0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756324AbbAZSGQ (ORCPT ); Mon, 26 Jan 2015 13:06:16 -0500 Received: by mail-lb0-f178.google.com with SMTP id u10so8974535lbd.9; Mon, 26 Jan 2015 10:06:14 -0800 (PST) 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=bilu6AsTu+RvKCXmGEwZAC66Oku5OCsQjxEomIqWCGQ=; b=YzDrYjfkVf709xhDjkb/MBMfXFWQi1EnuhFBik5CBSqzONKxl9mg9H5uM++RsRE3PY IQIw6BE25Azz/zDQrM8x7ygwg3Exi+Mid2dFaHNwzMI+r2ikHZmzAhOimsr/zQpjhtH7 iQfLuJEnmN9CkZfQZGdyhZFxdHh7URYClISdg8bgtcUeyrzWuG99JSU7RfQqMgiOEMXJ QvSpxP/f32OWOf9C/eo0awWQ/aY4Oi8qfujokALbmCChSyy41z06uKtzQ7+YqJENAUVm mPTQDRcQA1DrmSzEHDUk2DBTPaXp+V7qTH2CqBwnwOHbdYqpRLwFbOl6cwQyO0Xfu+8F Ghug== X-Received: by 10.112.41.234 with SMTP id i10mr22971572lbl.25.1422295574260; Mon, 26 Jan 2015 10:06:14 -0800 (PST) Received: from xi.terra (s83-177-171-8.cust.tele2.se. [83.177.171.8]) by mx.google.com with ESMTPSA id x6sm508696lad.46.2015.01.26.10.06.12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Jan 2015 10:06:13 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.84) (envelope-from ) id 1YFo3A-0001e2-Aw; Mon, 26 Jan 2015 19:06:12 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 1/2] gpio: sysfs: fix gpio-chip device-attribute leak Date: Mon, 26 Jan 2015 19:05:59 +0100 Message-Id: <1422295560-6284-2-git-send-email-johan@kernel.org> X-Mailer: git-send-email 2.0.5 In-Reply-To: <1422295560-6284-1-git-send-email-johan@kernel.org> References: <1422295496-6194-1-git-send-email-johan@kernel.org> <1422295560-6284-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 Commit 121b6a79955a3a3fd7bbb9b8cb88d5b9dad6283d upstream. The gpio-chip device attributes were never destroyed when the device was removed. Fix by using device_create_with_groups() to create the device attributes of the chip class device. Note that this also fixes the attribute-creation race with userspace. Fixes: d8f388d8dc8d ("gpio: sysfs interface") Cc: stable # v2.6.27+ Signed-off-by: Johan Hovold Signed-off-by: Linus Walleij [johan: fix leak without device_create_with_groups, which wasn't introduced until 3.11 ] Signed-off-by: Johan Hovold --- drivers/gpio/gpiolib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0dee0e0c247a..bc3d59efe80b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -627,7 +627,7 @@ static ssize_t chip_ngpio_show(struct device *dev, } static DEVICE_ATTR(ngpio, 0444, chip_ngpio_show, NULL); -static const struct attribute *gpiochip_attrs[] = { +static struct attribute *gpiochip_attrs[] = { &dev_attr_base.attr, &dev_attr_label.attr, &dev_attr_ngpio.attr, @@ -635,7 +635,7 @@ static const struct attribute *gpiochip_attrs[] = { }; static const struct attribute_group gpiochip_attr_group = { - .attrs = (struct attribute **) gpiochip_attrs, + .attrs = gpiochip_attrs, }; /* @@ -1036,6 +1036,7 @@ static void gpiochip_unexport(struct gpio_chip *chip) mutex_lock(&sysfs_lock); dev = class_find_device(&gpio_class, NULL, chip, match_export); if (dev) { + sysfs_remove_group(&dev->kobj, &gpiochip_attr_group); put_device(dev); device_unregister(dev); chip->exported = 0;