public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: dtor_core@ameritech.net
Subject: [PATCH] Make attributes names const char *
Date: Mon, 20 Jun 2005 15:59:21 -0700	[thread overview]
Message-ID: <11193083612312@kroah.com> (raw)
In-Reply-To: <11193083613036@kroah.com>

[PATCH] Make attributes names const char *

sysfs: make attributes and attribute_group's names const char *

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
commit d48593bf208e0d046c35fb0707ae5b23fef8c4ff
tree 8ee1375b7c7725c11238716646266d9a6d7fbc9f
parent 8d790d74085833ba2a3e84b5bcd683be4981c29a
author Dmitry Torokhov <dtor_core@ameritech.net> Fri, 29 Apr 2005 00:58:46 -0500
committer Greg Kroah-Hartman <gregkh@suse.de> Mon, 20 Jun 2005 15:15:01 -0700

 drivers/infiniband/core/sysfs.c |  122 ++++++++++++++++-----------------------
 drivers/pci/pci-sysfs.c         |   13 ++--
 include/linux/sysfs.h           |    4 +
 3 files changed, 59 insertions(+), 80 deletions(-)

diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -40,9 +40,7 @@ struct ib_port {
 	struct kobject         kobj;
 	struct ib_device      *ibdev;
 	struct attribute_group gid_group;
-	struct attribute     **gid_attr;
 	struct attribute_group pkey_group;
-	struct attribute     **pkey_attr;
 	u8                     port_num;
 };
 
@@ -60,8 +58,9 @@ struct port_attribute port_attr_##_name 
 struct port_attribute port_attr_##_name = __ATTR_RO(_name)
 
 struct port_table_attribute {
-	struct port_attribute attr;
-	int                   index;
+	struct port_attribute	attr;
+	char			name[8];
+	int			index;
 };
 
 static ssize_t port_attr_show(struct kobject *kobj,
@@ -398,17 +397,16 @@ static void ib_port_release(struct kobje
 	struct attribute *a;
 	int i;
 
-	for (i = 0; (a = p->gid_attr[i]); ++i) {
-		kfree(a->name);
+	for (i = 0; (a = p->gid_group.attrs[i]); ++i)
 		kfree(a);
-	}
 
-	for (i = 0; (a = p->pkey_attr[i]); ++i) {
-		kfree(a->name);
+	kfree(p->gid_group.attrs);
+
+	for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
 		kfree(a);
-	}
 
-	kfree(p->gid_attr);
+	kfree(p->pkey_group.attrs);
+
 	kfree(p);
 }
 
@@ -449,58 +447,45 @@ static int ib_device_hotplug(struct clas
 	return 0;
 }
 
-static int alloc_group(struct attribute ***attr,
-		       ssize_t (*show)(struct ib_port *,
-				       struct port_attribute *, char *buf),
-		       int len)
+static struct attribute **
+alloc_group_attrs(ssize_t (*show)(struct ib_port *,
+				  struct port_attribute *, char *buf),
+		  int len)
 {
-	struct port_table_attribute ***tab_attr =
-		(struct port_table_attribute ***) attr;
+	struct attribute **tab_attr;
+	struct port_table_attribute *element;
 	int i;
-	int ret;
-
-	*tab_attr = kmalloc((1 + len) * sizeof *tab_attr, GFP_KERNEL);
-	if (!*tab_attr)
-		return -ENOMEM;
 
-	memset(*tab_attr, 0, (1 + len) * sizeof *tab_attr);
-
-	for (i = 0; i < len; ++i) {
-		(*tab_attr)[i] = kmalloc(sizeof *(*tab_attr)[i], GFP_KERNEL);
-		if (!(*tab_attr)[i]) {
-			ret = -ENOMEM;
-			goto err;
-		}
-		memset((*tab_attr)[i], 0, sizeof *(*tab_attr)[i]);
-		(*tab_attr)[i]->attr.attr.name = kmalloc(8, GFP_KERNEL);
-		if (!(*tab_attr)[i]->attr.attr.name) {
-			ret = -ENOMEM;
+	tab_attr = kcalloc(1 + len, sizeof(struct attribute *), GFP_KERNEL);
+	if (!tab_attr)
+		return NULL;
+
+	for (i = 0; i < len; i++) {
+		element = kcalloc(1, sizeof(struct port_table_attribute),
+				  GFP_KERNEL);
+		if (!element)
 			goto err;
-		}
 
-		if (snprintf((*tab_attr)[i]->attr.attr.name, 8, "%d", i) >= 8) {
-			ret = -ENOMEM;
+		if (snprintf(element->name, sizeof(element->name),
+			     "%d", i) >= sizeof(element->name))
 			goto err;
-		}
-
-		(*tab_attr)[i]->attr.attr.mode  = S_IRUGO;
-		(*tab_attr)[i]->attr.attr.owner = THIS_MODULE;
-		(*tab_attr)[i]->attr.show       = show;
-		(*tab_attr)[i]->index           = i;
-	}
 
-	return 0;
+		element->attr.attr.name  = element->name;
+		element->attr.attr.mode  = S_IRUGO;
+		element->attr.attr.owner = THIS_MODULE;
+		element->attr.show       = show;
+		element->index		 = i;
 
-err:
-	for (i = 0; i < len; ++i) {
-		if ((*tab_attr)[i])
-			kfree((*tab_attr)[i]->attr.attr.name);
-		kfree((*tab_attr)[i]);
+		tab_attr[i] = &element->attr.attr;
 	}
 
-	kfree(*tab_attr);
+	return tab_attr;
 
-	return ret;
+err:
+	while (--i >= 0)
+		kfree(tab_attr[i]);
+	kfree(tab_attr);
+	return NULL;
 }
 
 static int add_port(struct ib_device *device, int port_num)
@@ -541,23 +526,20 @@ static int add_port(struct ib_device *de
 	if (ret)
 		goto err_put;
 
-	ret = alloc_group(&p->gid_attr, show_port_gid, attr.gid_tbl_len);
-	if (ret)
-		goto err_remove_pma;
-
 	p->gid_group.name  = "gids";
-	p->gid_group.attrs = p->gid_attr;
+	p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
+	if (!p->gid_group.attrs)
+		goto err_remove_pma;
 
 	ret = sysfs_create_group(&p->kobj, &p->gid_group);
 	if (ret)
 		goto err_free_gid;
 
-	ret = alloc_group(&p->pkey_attr, show_port_pkey, attr.pkey_tbl_len);
-	if (ret)
-		goto err_remove_gid;
-
 	p->pkey_group.name  = "pkeys";
-	p->pkey_group.attrs = p->pkey_attr;
+	p->pkey_group.attrs = alloc_group_attrs(show_port_pkey,
+						attr.pkey_tbl_len);
+	if (!p->pkey_group.attrs)
+		goto err_remove_gid;
 
 	ret = sysfs_create_group(&p->kobj, &p->pkey_group);
 	if (ret)
@@ -568,23 +550,19 @@ static int add_port(struct ib_device *de
 	return 0;
 
 err_free_pkey:
-	for (i = 0; i < attr.pkey_tbl_len; ++i) {
-		kfree(p->pkey_attr[i]->name);
-		kfree(p->pkey_attr[i]);
-	}
+	for (i = 0; i < attr.pkey_tbl_len; ++i)
+		kfree(p->pkey_group.attrs[i]);
 
-	kfree(p->pkey_attr);
+	kfree(p->pkey_group.attrs);
 
 err_remove_gid:
 	sysfs_remove_group(&p->kobj, &p->gid_group);
 
 err_free_gid:
-	for (i = 0; i < attr.gid_tbl_len; ++i) {
-		kfree(p->gid_attr[i]->name);
-		kfree(p->gid_attr[i]);
-	}
+	for (i = 0; i < attr.gid_tbl_len; ++i)
+		kfree(p->gid_group.attrs[i]);
 
-	kfree(p->gid_attr);
+	kfree(p->gid_group.attrs);
 
 err_remove_pma:
 	sysfs_remove_group(&p->kobj, &pma_group);
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -339,16 +339,17 @@ pci_create_resource_files(struct pci_dev
 		if (!pci_resource_len(pdev, i))
 			continue;
 
-		res_attr = kmalloc(sizeof(*res_attr) + 10, GFP_ATOMIC);
+		/* allocate attribute structure, piggyback attribute name */
+		res_attr = kcalloc(1, sizeof(*res_attr) + 10, GFP_ATOMIC);
 		if (res_attr) {
-			memset(res_attr, 0, sizeof(*res_attr) + 10);
+			char *res_attr_name = (char *)(res_attr + 1);
+
 			pdev->res_attr[i] = res_attr;
-			/* Allocated above after the res_attr struct */
-			res_attr->attr.name = (char *)(res_attr + 1);
-			sprintf(res_attr->attr.name, "resource%d", i);
-			res_attr->size = pci_resource_len(pdev, i);
+			sprintf(res_attr_name, "resource%d", i);
+			res_attr->attr.name = res_attr_name;
 			res_attr->attr.mode = S_IRUSR | S_IWUSR;
 			res_attr->attr.owner = THIS_MODULE;
+			res_attr->size = pci_resource_len(pdev, i);
 			res_attr->mmap = pci_mmap_resource;
 			res_attr->private = &pdev->resource[i];
 			sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -16,13 +16,13 @@ struct kobject;
 struct module;
 
 struct attribute {
-	char			* name;
+	const char		* name;
 	struct module 		* owner;
 	mode_t			mode;
 };
 
 struct attribute_group {
-	char			* name;
+	const char		* name;
 	struct attribute	** attrs;
 };
 


  reply	other threads:[~2005-06-21  4:29 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-20 22:55 [GIT PATCH] Driver core changes for 2.6.12 Greg KH
2005-06-20 22:59 ` [PATCH] sysfs_{create|remove}_link should take const char * Greg KH
2005-06-20 22:59   ` [PATCH] kobject_hotplug() should use kobject_name() Greg KH
2005-06-20 22:59     ` [PATCH] Make kobject's name be const char * Greg KH
2005-06-20 22:59       ` [PATCH] kset_hotplug_ops->name shoudl return " Greg KH
2005-06-20 22:59         ` [PATCH] make driver's name be " Greg KH
2005-06-20 22:59           ` Greg KH [this message]
2005-06-20 22:59             ` [PATCH] sysfs: (driver/base) if show/store is missing return -EIO Greg KH
2005-06-20 22:59               ` [PATCH] sysfs: " Greg KH
2005-06-20 22:59                 ` [PATCH] sysfs: (driver/pci) " Greg KH
2005-06-20 22:59                   ` [PATCH] sysfs: (driver/block) " Greg KH
2005-06-20 22:59                     ` [PATCH] sysfs: (rest) " Greg KH
2005-06-20 22:59                       ` [PATCH] INPUT: move to use the new class code, instead of class_simple Greg KH
2005-06-20 22:59                         ` [PATCH] tty: " Greg KH
2005-06-20 22:59                           ` [PATCH] CLASS: move a "simple" class logic into the class core Greg KH
2005-06-20 22:59                             ` [PATCH] class: convert sound/* to use the new class api instead of class_simple Greg KH
2005-06-20 22:59                               ` [PATCH] USB: move the usb hcd code to use the new class code Greg KH
2005-06-20 22:59                                 ` [PATCH] class: convert drivers/block/* to use the new class api instead of class_simple Greg KH
2005-06-20 22:59                                   ` [PATCH] class: convert drivers/ieee1394/* " Greg KH
2005-06-20 22:59                                     ` [PATCH] class: convert drivers/char/* " Greg KH
2005-06-20 22:59                                       ` [PATCH] class: convert drivers/scsi/* " Greg KH
2005-06-20 22:59                                         ` [PATCH] class: convert drivers/* " Greg KH
2005-06-20 22:59                                           ` [PATCH] USB: trivial error path fix Greg KH
2005-06-20 22:59                                             ` [PATCH] class: convert arch/* to use the new class api instead of class_simple Greg KH
2005-06-20 22:59                                               ` [PATCH] class: convert the remaining class_simple users in the kernel to usee the new class api Greg KH
2005-06-20 22:59                                                 ` [PATCH] class: add kerneldoc for the new class functions Greg KH
2005-06-20 22:59                                                   ` [PATCH] class: remove class_simple code, as no one in the tree is using it anymore Greg KH
2005-06-20 22:59                                                     ` [PATCH] fix "make mandocs" after class_simple.c removal Greg KH
2005-06-20 22:59                                                       ` [PATCH] Add a semaphore to struct device to synchronize calls to its driver Greg KH
2005-06-20 22:59                                                         ` [PATCH] fix up ipmi code after class_simple.c removal Greg KH
2005-06-20 22:59                                                           ` [PATCH] Move device/driver code to drivers/base/dd.c Greg KH
2005-06-20 22:59                                                             ` [PATCH] Use driver_for_each_device() instead of manually walking list Greg KH
2005-06-20 22:59                                                               ` [PATCH] Use driver_for_each_device() in drivers/pnp/driver.c " Greg KH
2005-06-20 22:59                                                                 ` [PATCH] Add driver_for_each_device() Greg KH
2005-06-20 22:59                                                                   ` [PATCH] Add a klist to struct bus_type for its drivers Greg KH
2005-06-20 22:59                                                                     ` [PATCH] Add a klist to struct bus_type for its devices Greg KH
2005-06-20 22:59                                                                       ` [PATCH] Add initial implementation of klist helpers Greg KH
2005-06-20 22:59                                                                         ` [PATCH] Add a klist to struct device_driver for the devices bound to it Greg KH
2005-06-20 22:59                                                                           ` [PATCH] Remove the unused device_find() Greg KH
2005-06-20 22:59                                                                             ` [PATCH] Use bus_for_each_{dev,drv} for driver binding Greg KH
2005-06-20 22:59                                                                               ` [PATCH] add klist_node_attached() to determine if a node is on a list or not Greg KH
2005-06-20 22:59                                                                                 ` [PATCH] Fix up USB to use klist_node_attached() instead of list_empty() on lists that will go away Greg KH
2005-06-20 22:59                                                                                   ` [PATCH] Remove struct device::driver_list Greg KH
2005-06-20 22:59                                                                                     ` [PATCH] Fix up bus code and remove use of rwsem Greg KH
2005-06-20 22:59                                                                                       ` [PATCH] Remove struct device::bus_list Greg KH
2005-06-20 22:59                                                                                         ` [PATCH] Don't reference NULL klist pointer in klist_remove() Greg KH
2005-06-20 22:59                                                                                           ` [PATCH] Call klist_del() instead of klist_remove() Greg KH
2005-06-20 22:59                                                                                             ` [PATCH] Use device_for_each_child() to unregister devices in scsi_remove_target() Greg KH
2005-06-20 22:59                                                                                               ` [PATCH] use device_for_each_child() to properly access child devices Greg KH
2005-06-20 22:59                                                                                                 ` [PATCH] Use a klist for device child lists Greg KH
2005-06-20 22:59                                                                                                   ` [PATCH] Fix up bogus comment Greg KH
2005-06-20 22:59                                                                                                     ` [PATCH] driver core: change export symbol for driver_for_each_device() Greg KH
2005-06-20 22:59                                                                                                       ` [PATCH] Use device_for_each_child() to unregister devices in nodemgr_remove_host_dev() Greg KH
2005-06-20 22:59                                                                                                         ` [PATCH] use device_for_each_child() to properly access child devices Greg KH
2005-06-20 22:59                                                                                                           ` [PATCH] USB: fix build warning in usb core as pointed out by Andrew Greg KH
2005-06-20 22:59                                                                                                             ` [PATCH] Driver Core: fix bk-driver-core kills ppc64 Greg KH
2005-06-20 22:59                                                                                                               ` [PATCH] Fix typo in scdrv_init() Greg KH
2005-06-20 22:59                                                                                                                 ` [PATCH] Driver core: Fix up the driver and device iterators to be quieter Greg KH
2005-06-20 22:59                                                                                                                   ` [PATCH] usb: klist_node_attached() fix Greg KH
2005-06-20 22:59                                                                                                                     ` [PATCH] sn: fixes due to driver core changes Greg KH
2005-06-20 22:59                                                                                                                       ` [PATCH] driver core: Fix races in driver_detach() Greg KH
2005-06-20 22:59                                                                                                                         ` [PATCH] Driver Core: driver model doc update Greg KH
2005-06-20 22:59                                                                                                                           ` [PATCH] Driver core: unregister_node() for hotplug use Greg KH
2005-06-20 22:59                                                                                                                             ` [PATCH] usbcore: Don't call device_release_driver recursively Greg KH
2005-06-20 22:59                                                                                                                               ` [PATCH] libfs: add simple attribute files Greg KH
2005-06-20 22:59                                                                                                                                 ` [PATCH] Driver core: change device_attribute callbacks Greg KH
2005-06-20 22:59                                                                                                                                   ` [PATCH] driver core: fix error handling in bus_add_device Greg KH
2005-06-20 22:59                                                                                                                                     ` [PATCH] Driver core: Documentation: update device attribute callbacks Greg KH
2005-06-20 22:59                                                                                                                                       ` [PATCH] Driver Core: drivers/base - drivers/i2c/chips/adm1026.c: " Greg KH
2005-06-20 22:59                                                                                                                                         ` [PATCH] Driver Core: arch: " Greg KH
2005-06-20 22:59                                                                                                                                           ` [PATCH] Driver Core: drivers/i2c/chips/adm1031.c - lm75.c: " Greg KH
2005-06-20 22:59                                                                                                                                             ` [PATCH] Driver Core: drivers/i2c/chips/lm77.c - max1619.c: " Greg KH
2005-06-20 22:59                                                                                                                                               ` [PATCH] Driver Core: drivers/i2c/chips/pc87360.c - w83627hf.c: " Greg KH
2005-06-20 22:59                                                                                                                                                 ` [PATCH] Driver Core: drivers/char/raw3270.c - drivers/net/netiucv.c: " Greg KH
2005-06-20 22:59                                                                                                                                                   ` [PATCH] Driver Core: drivers/i2c/chips/w83781d.c - drivers/s390/block/dcssblk.c: " Greg KH
2005-06-20 22:59                                                                                                                                                     ` [PATCH] Driver Core: drivers/usb/input/aiptek.c - drivers/zorro/zorro-sysfs.c: " Greg KH
2005-06-20 22:59                                                                                                                                                       ` [PATCH] Driver Core: drivers/s390/net/qeth_sys.c - drivers/usb/gadget/pxa2xx_udc.c: " Greg KH
2005-06-20 22:59                                                                                                                                                         ` [PATCH] Driver Core: include: " Greg KH
2005-06-20 22:59                                                                                                                                                           ` [PATCH] I2C: drivers/i2c/chips/adm1026.c: use dynamic sysfs callbacks Greg KH
2005-06-20 22:59                                                                                                                                                             ` [PATCH] I2C: add i2c sensor_device_attribute and macros Greg KH
2005-06-20 22:59                                                                                                                                                               ` [PATCH] sysfs-iattr: attach sysfs_dirent before new inode Greg KH
2005-06-20 22:59                                                                                                                                                                 ` [PATCH] Driver core: Don't "lose" devices on suspend on failure Greg KH
2005-06-20 22:59                                                                                                                                                                   ` [PATCH] sysfs-iattr: set inode attributes Greg KH
2005-06-20 22:59                                                                                                                                                                     ` [PATCH] sysfs-iattr: add sysfs_setattr Greg KH
2005-06-20 22:59                                                                                                                                                                       ` [PATCH] SYSFS: fix PAGE_SIZE check Greg KH
2005-06-20 22:59                                                                                                                                                                         ` [PATCH] USB: fix show_modalias() function due to attribute change Greg KH
2005-06-20 22:59                                                                                                                                                                           ` [PATCH] PCI: " Greg KH
2005-07-06  0:38                                                                                               ` [PATCH] Use device_for_each_child() to unregister devices in scsi_remove_target() Patrick Mansfield
2005-07-12  0:20                                                                                                 ` Greg KH
2005-07-12  0:56                                                                                                   ` Patrick Mansfield
2005-06-21 11:42                                                                         ` [PATCH] Add initial implementation of klist helpers Rik van Riel
2005-06-21 23:13                                                                           ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11193083612312@kroah.com \
    --to=gregkh@suse.de \
    --cc=dtor_core@ameritech.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox