Skip to contentSkip to conversation

pcmcia: struct device - replace bus_id with dev_name(), dev_set_name()

PATCH Kay Sievers 2 participants 4 messages Nov 1, 2008 – Nov 2, 2008 Pcmcia

lore
Share & tools
lore
#0 lore raw

This patch is part of a larger patch series which will remove the "char bus_id[20]" name string from struct device. The device name is managed in the kobject anyway, and without any size limitation, and just needlessly copied into "struct device".

To set and read the device name dev_name(dev) and dev_set_name(dev) must be used. If your code uses static kobjects, which it shouldn't do, "const char *init_name" can be used to statically provide the name the registered device should have. At registration time, the init_name field is cleared, to enforce the use of dev_name(dev) to access the device name at a later time.

We need to get rid of all occurrences of bus_id in the entire tree to be able to enable the new interface. Please apply this patch, and possibly convert any remaining remaining occurrences of bus_id.

We want to submit a patch to -next, which will remove bus_id from "struct device", to find the remaining pieces to convert, and finally switch over to the new api, which will remove the 20 bytes array and does no longer have a size limitation.

Thanks,
Kay

From: Kay Sievers <[email protected]>
Subject: pcmcia: struct device - replace bus_id with dev_name(), dev_set_name()

---

drivers/pcmcia/cs.c +1 -1
index c68c5d3..5d0e60e 100644
@@ -226,7 +226,7 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
 	/* set proper values in socket->dev */
 	dev_set_drvdata(&socket->dev, socket);
 	socket->dev.class = &pcmcia_socket_class;
-	snprintf(socket->dev.bus_id, BUS_ID_SIZE, "pcmcia_socket%u", socket->sock);
+	dev_set_name(&socket->dev, "pcmcia_socket%u", socket->sock);
 
 	/* base address = 0, map = 0 */
 	socket->cis_mem.flags = 0;
drivers/pcmcia/ds.c +4 -5
index 7956602..7cff346 100644
@@ -622,7 +622,6 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
 {
 	struct pcmcia_device *p_dev, *tmp_dev;
 	unsigned long flags;
-	int bus_id_len;
 
 	s = pcmcia_get_socket(s);
 	if (!s)
@@ -650,12 +649,12 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
 	/* by default don't allow DMA */
 	p_dev->dma_mask = DMA_MASK_NONE;
 	p_dev->dev.dma_mask = &p_dev->dma_mask;
-	bus_id_len = sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no);
-
-	p_dev->devname = kmalloc(6 + bus_id_len + 1, GFP_KERNEL);
+	dev_set_name(&p_dev->dev, "%d.%d", p_dev->socket->sock, p_dev->device_no);
+	if (!dev_name(&p_dev->dev))
+		goto err_free;
+	p_dev->devname = kasprintf(GFP_KERNEL, "pcmcia%s", dev_name(&p_dev->dev));
 	if (!p_dev->devname)
 		goto err_free;
-	sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id);
 	ds_dev_dbg(3, &p_dev->dev, "devname is %s\n", p_dev->devname);
 
 	spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
drivers/pcmcia/rsrc_nonstatic.c +3 -3
index 17f4ecf..9ca22c7 100644
@@ -71,7 +71,7 @@ static DEFINE_MUTEX(rsrc_mutex);
 ======================================================================*/
 
 static struct resource *
-make_resource(resource_size_t b, resource_size_t n, int flags, char *name)
+make_resource(resource_size_t b, resource_size_t n, int flags, const char *name)
 {
 	struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
 
@@ -624,7 +624,7 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
 static struct resource *nonstatic_find_io_region(unsigned long base, int num,
 		   unsigned long align, struct pcmcia_socket *s)
 {
-	struct resource *res = make_resource(0, num, IORESOURCE_IO, s->dev.bus_id);
+	struct resource *res = make_resource(0, num, IORESOURCE_IO, dev_name(&s->dev));
 	struct socket_data *s_data = s->resource_data;
 	struct pcmcia_align_data data;
 	unsigned long min = base;
@@ -658,7 +658,7 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
 static struct resource * nonstatic_find_mem_region(u_long base, u_long num,
 		u_long align, int low, struct pcmcia_socket *s)
 {
-	struct resource *res = make_resource(0, num, IORESOURCE_MEM, s->dev.bus_id);
+	struct resource *res = make_resource(0, num, IORESOURCE_MEM, dev_name(&s->dev));
 	struct socket_data *s_data = s->resource_data;
 	struct pcmcia_align_data data;
 	unsigned long min, max;
maintainer Acked-by
#1 lore raw

Hi,

Quoted 6 lines · Kay Sievers

From: Kay Sievers <[email protected]>
Subject: pcmcia: struct device - replace bus_id with dev_name(), dev_set_name()

is this to go in via -pcmcia or via -driver-core?

drivers/pcmcia/cs.c int pcmcia_register_socket(struct pcmcia_socket *socket) · line 229

Quoted 10 lines
drivers/pcmcia/cs.c +1 -1
index c68c5d3..5d0e60e 100644
@@ -226,7 +226,7 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
 	/* set proper values in socket->dev */
 	dev_set_drvdata(&socket->dev, socket);
 	socket->dev.class = &pcmcia_socket_class;
-	snprintf(socket->dev.bus_id, BUS_ID_SIZE, "pcmcia_socket%u", socket->sock);
+	dev_set_name(&socket->dev, "pcmcia_socket%u", socket->sock);

In other places, you check for !dev_name() afterwards -- why not here?

Otherwise it is

Thanks!
Dominik

#2 lore raw
Quoted 9 lines · Dominik Brodowski
Quoted 6 lines · Kay Sievers

From: Kay Sievers <[email protected]>
Subject: pcmcia: struct device - replace bus_id with dev_name(), dev_set_name()

is this to go in via -pcmcia or via -driver-core?

Would be great if this goes through -pcmcia, and show up in -next soon, so we can continue to address the rest of the tree in -next, after the patches are merged from the subsystem trees.

Quoted 4 lines
Quoted 4 lines
drivers/pcmcia/cs.c +0 -0
index c68c5d3..5d0e60e 100644
Quoted 8 lines

drivers/pcmcia/cs.c int pcmcia_register_socket(struct pcmcia_socket *socket) · line 229

Quoted 6 lines
drivers/pcmcia/cs.c +1 -1
@@ -226,7 +226,7 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
      /* set proper values in socket->dev */
      dev_set_drvdata(&socket->dev, socket);
      socket->dev.class = &pcmcia_socket_class;
-     snprintf(socket->dev.bus_id, BUS_ID_SIZE, "pcmcia_socket%u", socket->sock);
+     dev_set_name(&socket->dev, "pcmcia_socket%u", socket->sock);

In other places, you check for !dev_name() afterwards -- why not here?

The name is used in the line just below setting it, which is why we need to check that it is not NULL. The other case, like in almost all other cases, the unlikely event of failing to set the name is handled by a failing call to device_register().

Thanks,
Kay

#3 lore raw

Kay,

Quoted 6 lines · Kay Sievers
Quoted 4 lines · Dominik Brodowski
Quoted 3 lines · Kay Sievers

From: Kay Sievers <[email protected]>
Subject: pcmcia: struct device - replace bus_id with dev_name(), dev_set_name()

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

is this to go in via -pcmcia or via -driver-core?

Would be great if this goes through -pcmcia, and show up in -next soon,

it's in -pcmcia now.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/pcmcia/cs.c +0 -0
index c68c5d3..5d0e60e 100644
Quoted 8 lines

drivers/pcmcia/cs.c int pcmcia_register_socket(struct pcmcia_socket *socket) · line 229

Quoted 6 lines
drivers/pcmcia/cs.c +1 -1
@@ -226,7 +226,7 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
      /* set proper values in socket->dev */
      dev_set_drvdata(&socket->dev, socket);
      socket->dev.class = &pcmcia_socket_class;
-     snprintf(socket->dev.bus_id, BUS_ID_SIZE, "pcmcia_socket%u", socket->sock);
+     dev_set_name(&socket->dev, "pcmcia_socket%u", socket->sock);

In other places, you check for !dev_name() afterwards -- why not here?

Quoted 4 lines

The name is used in the line just below setting it, which is why we need to check that it is not NULL. The other case, like in almost all other cases, the unlikely event of failing to set the name is handled by a failing call to device_register().

Ah, okay. Thanks.

Dominik