From patchwork Thu Aug 11 19:02:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Krutak X-Patchwork-Id: 9275853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 51FCD60780 for ; Thu, 11 Aug 2016 19:52:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F6B228715 for ; Thu, 11 Aug 2016 19:52:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3474828786; Thu, 11 Aug 2016 19:52:56 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 631A828715 for ; Thu, 11 Aug 2016 19:52:55 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 2C267267C92; Thu, 11 Aug 2016 21:52:54 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 51AA3267753; Thu, 11 Aug 2016 21:42:01 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 38CA42676C6; Thu, 11 Aug 2016 21:41:58 +0200 (CEST) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by alsa0.perex.cz (Postfix) with ESMTP id 6BF9D26774A for ; Thu, 11 Aug 2016 21:03:59 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id q128so955244wma.1 for ; Thu, 11 Aug 2016 12:03:59 -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=Du4boIyjSZbjVlRxJDqWO+lv+C2ZVlELE1L8Niwcx1M=; b=t5HM2gaxGatm0Rs82wZwHFYd7wRjJLOv7hc4mHNuZgNuJvZz3kXp9lUkIxaQ/RBVKj 3xMKz0NwxcZNzqH4T0v/pmeHSug+NxvZWMGHOjoj5rCDI905Eav+eu5JGitAtyFBXBQF aVUUSPTW+M9eLarSIjDnvc9pH529HuNomV4yYu+jRTH/Vg4ZviXLCWrQdQE3XxLPJW36 1HtFUUGe8ci0racgsxPwG1zn3K2zW65GoQyc5fo2yQ48B4UliUq4B/TdumQGBJ2pRTxj X9YSWN6mJVYpncrgQH3j2W59ohef1g8EbfrYfnmgc4dvNqw9d4nYyCUwcmG0iPYC7hES 8sPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Du4boIyjSZbjVlRxJDqWO+lv+C2ZVlELE1L8Niwcx1M=; b=L5nTxE+vl53ZO3Jv3Q7I0Girf01BOlKmrJMOsJz/hE1mjx0m9XAMD/UHSTCymj/yfG UZ3fq5hTzN0yjySxBy4GL7ZTz/LEaXXyPhM/4tsEfkMUGoPxTMM0tpHj2WmTDgSIg5w1 YAxL40lMZ6P/YgdzA9/Ilz1PuVJ1PsyL9uC8cdhukxfj9/V2aGjz/iSgfOEbfEl3My6A edE+wF3Wfx3jsvYD8tg54YAG4A1OP/DQc+6CftlOKHfprkPsrr2I29q1ds3dB5fRGkFQ rb0XtMI+rYiirlnYwBaYOqiUKSr5SXBZOEMI/2H0jD3k8UQcDLxxCK0X4Sv8VtbMkLVU VEGg== X-Gm-Message-State: AEkooutG9a+GZrjfaYUe86fzExr+8tQMg6cI16ndtoTBa9GVbtwVm/X8VzlVOW5FyOIB0g== X-Received: by 10.28.31.147 with SMTP id f141mr10355656wmf.69.1470942239129; Thu, 11 Aug 2016 12:03:59 -0700 (PDT) Received: from localhost.localdomain ([94.229.40.98]) by smtp.gmail.com with ESMTPSA id x6sm4001376wjk.26.2016.08.11.12.03.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Aug 2016 12:03:58 -0700 (PDT) From: Andrej Krutak To: alsa-devel@alsa-project.org Date: Thu, 11 Aug 2016 21:02:17 +0200 Message-Id: <1470942147-19848-6-git-send-email-dev@andree.sk> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470942147-19848-1-git-send-email-dev@andree.sk> References: <1470942147-19848-1-git-send-email-dev@andree.sk> Cc: Andrej Krutak Subject: [alsa-devel] [PATCH 05/15] ALSA: line6: Use device_create_file instead of snd_card_add_dev_attr X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP The latter seems to create invalid configuration, the device pointer passed to the attr callbacks is not correct afterwards (results into segfaults when accessing the attributes). Signed-off-by: Andrej Krutak --- sound/usb/line6/podhd.c | 60 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c index 42fa376..f72803a 100644 --- a/sound/usb/line6/podhd.c +++ b/sound/usb/line6/podhd.c @@ -57,6 +57,9 @@ struct usb_line6_podhd { /* Firmware version */ int firmware_version; + + /* Flag whether the sysfs files were created */ + int devfiles_created; }; static struct snd_ratden podhd_ratden = { @@ -177,16 +180,37 @@ static ssize_t firmware_version_show(struct device *dev, static DEVICE_ATTR_RO(firmware_version); static DEVICE_ATTR_RO(serial_number); -static struct attribute *podhd_dev_attrs[] = { - &dev_attr_firmware_version.attr, - &dev_attr_serial_number.attr, - NULL -}; +/* + * Create sysfs entries. + */ +static int podhd_create_attrs(struct device *dev) +{ + int err; + struct usb_interface *interface = to_usb_interface(dev); + struct usb_line6_podhd *pod = usb_get_intfdata(interface); -static const struct attribute_group podhd_dev_attr_group = { - .name = "podhd", - .attrs = podhd_dev_attrs, -}; + err = device_create_file(dev, &dev_attr_firmware_version); + if (err < 0) + return err; + err = device_create_file(dev, &dev_attr_serial_number); + if (err < 0) + return err; + + pod->devfiles_created = 1; + return 0; +} + +static void podhd_remove_attrs(struct device *dev) +{ + struct usb_interface *interface = to_usb_interface(dev); + struct usb_line6_podhd *pod = usb_get_intfdata(interface); + + if (pod->devfiles_created) { + device_remove_file(dev, &dev_attr_firmware_version); + device_remove_file(dev, &dev_attr_serial_number); + pod->devfiles_created = 0; + } +} /* * POD X3 startup procedure. @@ -281,6 +305,14 @@ static int podhd_startup_finalize(struct usb_line6_podhd *pod) { struct usb_line6 *line6 = &pod->line6; + if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) { + /* create sysfs entries: */ + int err = podhd_create_attrs(line6->ifcdev); + + if (err < 0) + return err; + } + /* ALSA audio interface: */ return snd_card_register(line6->card); } @@ -288,8 +320,11 @@ static int podhd_startup_finalize(struct usb_line6_podhd *pod) static void podhd_disconnect(struct usb_line6 *line6) { struct usb_line6_podhd *pod = (struct usb_line6_podhd *)line6; + struct device *dev = line6->ifcdev; if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) { + podhd_remove_attrs(dev); + del_timer_sync(&pod->startup_timer); cancel_work_sync(&pod->startup_work); } @@ -306,13 +341,6 @@ static int podhd_init(struct usb_line6 *line6, line6->disconnect = podhd_disconnect; - if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) { - /* create sysfs entries: */ - err = snd_card_add_dev_attr(line6->card, &podhd_dev_attr_group); - if (err < 0) - return err; - } - /* initialize MIDI subsystem: */ err = line6_init_midi(line6); if (err < 0)