From patchwork Fri Jan 11 16:29:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 10760281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAE331390 for ; Fri, 11 Jan 2019 16:29:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B82EE2A076 for ; Fri, 11 Jan 2019 16:29:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC61C2A07B; Fri, 11 Jan 2019 16:29:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A7512A076 for ; Fri, 11 Jan 2019 16:29:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731013AbfAKQ3t (ORCPT ); Fri, 11 Jan 2019 11:29:49 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41993 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729349AbfAKQ3t (ORCPT ); Fri, 11 Jan 2019 11:29:49 -0500 Received: by mail-wr1-f68.google.com with SMTP id q18so15808686wrx.9; Fri, 11 Jan 2019 08:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=y0AxGB2q4g9ILXTjTwoDsLoFG0VcILdFKNViSLsFn5s=; b=WDUr2d9M0JM0L692oGnTNsLFDAy1nLV/0AAlN0sOVeEanG6ddlLHND5Gvyme4vFMQw 561uRygGlq/I9tVNkPrV/AZA9kpac+ZUnRYLOHE4u519BBukTTxG1y4Gp3qE95vndlSw pIX2N9FQoZ4QdTBFbpX1yiloBP6/+5QMLGAhRtLyMf+8G4xJtuOBrtyn6aNdqphmn7Zc m9R5s7DLGboUumWwoQEQ5w0CSqciH3CK/sd9DAJMLKic4xD5cAEc6OpI5vtYejq8vgY9 iHo+I6YCh+PHNphejENB5DoEl5cXPe12v3PxWUxu9Nsg+etOe6IOZVtbx9IGXR0tBSZs 6Uog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=y0AxGB2q4g9ILXTjTwoDsLoFG0VcILdFKNViSLsFn5s=; b=J21/sxLmZyrAWVR125og0Y9sfn6nP32jovWLNp5whwRXfYY3/f3UPqo6eEYFERjYH+ erVq5Bxn+NiLnNcqqQulVq6X7fTYyg89APBqtalr74283t6xwjGlXQp9NkHQ0cQp+ne0 6T7mB7z8IM/6OxwoLWyNonH6KHlk9p22yO4CL90h4bUvC76g8QLHBOLBfRdx3cFJadAe pSZelWfNb7CY1SGvz36CQPTlkKFodsJzPrBQsDq3qyjBFI+rRT5I9vzgyQlz0qAf4lcG QF5rCJ/VsAU+oicSbYO7B371cs4KhH3mGxIBEDdY18dwmAiKkpvaCtym2NbYFpNNj01P ETSg== X-Gm-Message-State: AJcUukcp2RtROCTxqd+LJZfP1K6ie1M2A9onWkhJcHRSYImGlo6Rp/dx yBErxJcnkQ3Scx664MsppoSEdj26 X-Google-Smtp-Source: ALg8bN6bGOGuXv7B6nyPtpn+Jfvxxf+bMcGPLrpVaph/UqKJbo7xyZz0jGe8zaGPsxmROVbWYomt9g== X-Received: by 2002:adf:ee89:: with SMTP id b9mr14667021wro.246.1547224186691; Fri, 11 Jan 2019 08:29:46 -0800 (PST) Received: from debian64.daheim (p4FD09B7A.dip0.t-ipconnect.de. [79.208.155.122]) by smtp.gmail.com with ESMTPSA id t199sm7505716wmt.1.2019.01.11.08.29.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jan 2019 08:29:45 -0800 (PST) Received: from chuck by debian64.daheim with local (Exim 4.92-RC4) (envelope-from ) id 1ghzgn-0008Ea-1Y; Fri, 11 Jan 2019 17:29:45 +0100 From: Christian Lamparter To: linux-usb@vger.kernel.org, linux-leds@vger.kernel.org Cc: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jacek Anaszewski , Greg Kroah-Hartman Subject: [PATCH v2] leds: fix regression in usbport led trigger Date: Fri, 11 Jan 2019 17:29:45 +0100 Message-Id: <20190111162945.31612-1-chunkeey@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The patch "usb: simplify usbport trigger" together with "leds: triggers: add device attribute support" caused an regression for the usbport trigger. it will no longer enumerate any active usb hub ports under the "ports" directory in the sysfs class directory, if the usb host drivers are fully initialized before the usbport trigger was loaded. The reason is that the usbport driver tries to register the sysfs entries during the activate() callback. And this will fail with -2 / ENOENT because the patch "leds: triggers: add device attribute support" made it so that the sysfs "ports" group was only being added after the activate() callback succeeded. This version of the patch reverts parts of the "usb: simplify usbport trigger" patch and restores usbport trigger's functionality. Fixes: 6f7b0bad8839 ("usb: simplify usbport trigger") Signed-off-by: Christian Lamparter Acked-by: Jacek Anaszewski --- Let's see if linux-usb is still on holiday or not ;). --- drivers/usb/core/ledtrig-usbport.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/usb/core/ledtrig-usbport.c b/drivers/usb/core/ledtrig-usbport.c index dc7f7fd71684..c12ac56606c3 100644 --- a/drivers/usb/core/ledtrig-usbport.c +++ b/drivers/usb/core/ledtrig-usbport.c @@ -119,11 +119,6 @@ static const struct attribute_group ports_group = { .attrs = ports_attrs, }; -static const struct attribute_group *ports_groups[] = { - &ports_group, - NULL -}; - /*************************************** * Adding & removing ports ***************************************/ @@ -307,6 +302,7 @@ static int usbport_trig_notify(struct notifier_block *nb, unsigned long action, static int usbport_trig_activate(struct led_classdev *led_cdev) { struct usbport_trig_data *usbport_data; + int err; usbport_data = kzalloc(sizeof(*usbport_data), GFP_KERNEL); if (!usbport_data) @@ -315,6 +311,9 @@ static int usbport_trig_activate(struct led_classdev *led_cdev) /* List of ports */ INIT_LIST_HEAD(&usbport_data->ports); + err = sysfs_create_group(&led_cdev->dev->kobj, &ports_group); + if (err) + goto err_free; usb_for_each_dev(usbport_data, usbport_trig_add_usb_dev_ports); usbport_trig_update_count(usbport_data); @@ -322,8 +321,11 @@ static int usbport_trig_activate(struct led_classdev *led_cdev) usbport_data->nb.notifier_call = usbport_trig_notify; led_set_trigger_data(led_cdev, usbport_data); usb_register_notify(&usbport_data->nb); - return 0; + +err_free: + kfree(usbport_data); + return err; } static void usbport_trig_deactivate(struct led_classdev *led_cdev) @@ -335,6 +337,8 @@ static void usbport_trig_deactivate(struct led_classdev *led_cdev) usbport_trig_remove_port(usbport_data, port); } + sysfs_remove_group(&led_cdev->dev->kobj, &ports_group); + usb_unregister_notify(&usbport_data->nb); kfree(usbport_data); @@ -344,7 +348,6 @@ static struct led_trigger usbport_led_trigger = { .name = "usbport", .activate = usbport_trig_activate, .deactivate = usbport_trig_deactivate, - .groups = ports_groups, }; static int __init usbport_trig_init(void)