Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3335591imu; Sun, 11 Nov 2018 12:38:25 -0800 (PST) X-Google-Smtp-Source: AJdET5c0c7ZEd+uAaallYWb/8nCK9ytzf7o0z9qDqkOQYC60OCuRejEznkEPGuVwVf1vAaItd5vN X-Received: by 2002:a63:ff62:: with SMTP id s34mr15137375pgk.325.1541968705369; Sun, 11 Nov 2018 12:38:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968705; cv=none; d=google.com; s=arc-20160816; b=Z81CFGS8cQOTQK79sf0fqVErL2iRcsj+i7AVHVQcFCXr4PJi4zkSI8P95SWBVWkMrz PuMtpID+jU5pZqZl0H1DsqXo6bmqUGbi5OSFnUCMX9aE5Y8gqX0aty5gflF+Wq0jCGRT 3MjnCueH7d79eJGZ9Ze/HLt5Yb+RxEau7lrVwn2/N/TMgWg+iddf1JZB2kDIeUGV8JhU d1cQD7MLm4oBWBblOxw58YZHrqm9yUq4f521ybEzisEiNpD+eNUbIEPY2HxkBh3dYi1l 6jfVd+5Y3PifEoG92N5C2q/yN/IRfmAgOEuxsoDBnz2pi3BGpuJgxscNr+N90CspfnG0 Bv/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=nc4yf0RmJNTHSqmR7/2mDBkPmARRXMggnXgslnBlwBc=; b=LJDGXC7qyxNTwSHpPcipO7dP0yV1YC8sCtMiSYjEtSTfjIacIuKN5fHnQTDAA8HNUu 6Axm3NbgKsUbyIMymkh+MokbMAOI7K3Newgl+QtzTSGYobwS/3xInM+qErIFRz1I772b zVtXNqqfT/EGeFmBC9f0eeySvos3cTNuE2k5oHXCWj9Tnx/bEWLJS9HLS5BOYGxFVhWr f7ddORfkmKZHZNQv/Rd2vj1THY7Xvd1ml2xX2l/aEA/511LOSKfDpYJK15eDCvAKzcdD D3EdcemOKCPrAjngB+w9klFhM3QIN2JBeJsghbZ5KoDvwKHZKx1MDoivIx2pr+0w3fYd pSmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12-v6si14976900pfi.99.2018.11.11.12.38.10; Sun, 11 Nov 2018 12:38:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730147AbeKLFsL (ORCPT + 99 others); Mon, 12 Nov 2018 00:48:11 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:49678 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730056AbeKLFsK (ORCPT ); Mon, 12 Nov 2018 00:48:10 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsW-0000lM-4B; Sun, 11 Nov 2018 19:58:40 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsT-0001ay-4f; Sun, 11 Nov 2018 19:58:37 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Takashi Iwai" , "David Vrabel" , "David S. Miller" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 166/366] xen-netfront: Use static attribute groups for sysfs entries In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit 27b917e54bed7156c2b0249969ace34a5f585626 upstream. Instead of manual calls of device_create_file() and device_remove_files(), assign the static attribute groups to netdev groups array. This simplifies the code and avoids the possible races. Signed-off-by: Takashi Iwai Acked-by: David Vrabel Signed-off-by: David S. Miller [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/net/xen-netfront.c | 62 ++++++++++---------------------------- 1 file changed, 16 insertions(+), 46 deletions(-) --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -228,11 +228,7 @@ static grant_ref_t xennet_get_rx_ref(str } #ifdef CONFIG_SYSFS -static int xennet_sysfs_addif(struct net_device *netdev); -static void xennet_sysfs_delif(struct net_device *netdev); -#else /* !CONFIG_SYSFS */ -#define xennet_sysfs_addif(dev) (0) -#define xennet_sysfs_delif(dev) do { } while (0) +static const struct attribute_group xennet_dev_group; #endif static bool xennet_can_sg(struct net_device *dev) @@ -1399,20 +1395,15 @@ static int netfront_probe(struct xenbus_ info = netdev_priv(netdev); dev_set_drvdata(&dev->dev, info); - +#ifdef CONFIG_SYSFS + info->netdev->sysfs_groups[0] = &xennet_dev_group; +#endif err = register_netdev(info->netdev); if (err) { pr_warn("%s: register_netdev err=%d\n", __func__, err); goto fail; } - err = xennet_sysfs_addif(info->netdev); - if (err) { - unregister_netdev(info->netdev); - pr_warn("%s: add sysfs failed err=%d\n", __func__, err); - goto fail; - } - return 0; fail: @@ -2278,39 +2269,20 @@ static ssize_t show_rxbuf_cur(struct dev return sprintf(buf, "0\n"); } -static struct device_attribute xennet_attrs[] = { - __ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf_min, store_rxbuf_min), - __ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf_max, store_rxbuf_max), - __ATTR(rxbuf_cur, S_IRUGO, show_rxbuf_cur, NULL), +static DEVICE_ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf_min, store_rxbuf_min); +static DEVICE_ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf_max, store_rxbuf_max); +static DEVICE_ATTR(rxbuf_cur, S_IRUGO, show_rxbuf_cur, NULL); + +static struct attribute *xennet_dev_attrs[] = { + &dev_attr_rxbuf_min.attr, + &dev_attr_rxbuf_max.attr, + &dev_attr_rxbuf_cur.attr, + NULL }; -static int xennet_sysfs_addif(struct net_device *netdev) -{ - int i; - int err; - - for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) { - err = device_create_file(&netdev->dev, - &xennet_attrs[i]); - if (err) - goto fail; - } - return 0; - - fail: - while (--i >= 0) - device_remove_file(&netdev->dev, &xennet_attrs[i]); - return err; -} - -static void xennet_sysfs_delif(struct net_device *netdev) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) - device_remove_file(&netdev->dev, &xennet_attrs[i]); -} - +static const struct attribute_group xennet_dev_group = { + .attrs = xennet_dev_attrs +}; #endif /* CONFIG_SYSFS */ static const struct xenbus_device_id netfront_ids[] = { @@ -2328,8 +2300,6 @@ static int xennet_remove(struct xenbus_d xennet_disconnect_backend(info); - xennet_sysfs_delif(info->netdev); - unregister_netdev(info->netdev); if (num_queues) {