[PATCH] Make platform_device.id an int

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jean Delvare
Date: Sunday, September 9, 2007 - 3:54 am

While platform_device.id is a u32, platform_device_add() handles "-1"
as a special id value. This has potential for confusion and bugs.
Making it an int instead should prevent problems from happening in
the future.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
---
I still believe that we can further clean up this area, but that will
do for now.

 drivers/base/platform.c         |    7 ++++---
 include/linux/platform_device.h |    7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

--- linux-2.6.23-rc5.orig/drivers/base/platform.c	2007-07-09 14:49:46.000000000 +0200
+++ linux-2.6.23-rc5/drivers/base/platform.c	2007-09-09 12:15:24.000000000 +0200
@@ -166,7 +166,7 @@ static void platform_device_release(stru
  *	the device isn't being dynamically allocated as a legacy "probe the
  *	hardware" driver, infrastructure code should reverse this marking.
  */
-struct platform_device *platform_device_alloc(const char *name, unsigned int id)
+struct platform_device *platform_device_alloc(const char *name, int id)
 {
 	struct platform_object *pa;
 
@@ -256,7 +256,8 @@ int platform_device_add(struct platform_
 	pdev->dev.bus = &platform_bus_type;
 
 	if (pdev->id != -1)
-		snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s.%u", pdev->name, pdev->id);
+		snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s.%d", pdev->name,
+			 pdev->id);
 	else
 		strlcpy(pdev->dev.bus_id, pdev->name, BUS_ID_SIZE);
 
@@ -370,7 +371,7 @@ EXPORT_SYMBOL_GPL(platform_device_unregi
  *	the Linux driver model.  In particular, when such drivers are built
  *	as modules, they can't be "hotplugged".
  */
-struct platform_device *platform_device_register_simple(char *name, unsigned int id,
+struct platform_device *platform_device_register_simple(char *name, int id,
 							struct resource *res, unsigned int num)
 {
 	struct platform_device *pdev;
--- linux-2.6.23-rc5.orig/include/linux/platform_device.h	2007-02-04 19:44:54.000000000 +0100
+++ linux-2.6.23-rc5/include/linux/platform_device.h	2007-09-09 12:15:41.000000000 +0200
@@ -15,7 +15,7 @@
 
 struct platform_device {
 	const char	* name;
-	u32		id;
+	int		id;
 	struct device	dev;
 	u32		num_resources;
 	struct resource	* resource;
@@ -35,9 +35,10 @@ extern struct resource *platform_get_res
 extern int platform_get_irq_byname(struct platform_device *, char *);
 extern int platform_add_devices(struct platform_device **, int);
 
-extern struct platform_device *platform_device_register_simple(char *, unsigned int, struct resource *, unsigned int);
+extern struct platform_device *platform_device_register_simple(char *, int id,
+					struct resource *, unsigned int);
 
-extern struct platform_device *platform_device_alloc(const char *name, unsigned int id);
+extern struct platform_device *platform_device_alloc(const char *name, int id);
 extern int platform_device_add_resources(struct platform_device *pdev, struct resource *res, unsigned int num);
 extern int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size);
 extern int platform_device_add(struct platform_device *pdev);


-- 
Jean Delvare
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Platform device id, Jean Delvare, (Fri Sep 7, 6:35 am)
Re: Platform device id, Dmitry Torokhov, (Fri Sep 7, 7:58 am)
Re: Platform device id, Jean Delvare, (Fri Sep 7, 9:36 am)
Re: Platform device id, David Brownell, (Fri Sep 7, 9:41 am)
Re: Platform device id, Henrique de Moraes H ..., (Fri Sep 7, 1:56 pm)
Re: Platform device id, Henrique de Moraes H ..., (Fri Sep 7, 2:00 pm)
Re: Platform device id, David Brownell, (Fri Sep 7, 2:41 pm)
Re: Platform device id, Henrique de Moraes H ..., (Fri Sep 7, 3:04 pm)
Re: Platform device id, David Brownell, (Fri Sep 7, 5:18 pm)
Re: Platform device id, Henrique de Moraes H ..., (Fri Sep 7, 8:50 pm)
Re: Platform device id, Jean Delvare, (Sat Sep 8, 1:40 am)
Re: Platform device id, Jean Delvare, (Sat Sep 8, 1:55 am)
Re: Platform device id, Greg KH, (Sat Sep 8, 6:30 am)
[PATCH] Make platform_device.id an int, Jean Delvare, (Sun Sep 9, 3:54 am)
Re: Platform device id, Henrique de Moraes H ..., (Mon Sep 10, 3:45 pm)
Re: Platform device id, Henrique de Moraes H ..., (Mon Sep 10, 3:52 pm)
Re: Platform device id, Jean Delvare, (Tue Sep 11, 12:43 am)
Re: Platform device id, Henrique de Moraes H ..., (Tue Sep 11, 6:44 am)
Re: Platform device id, Jean Delvare, (Tue Sep 11, 7:05 am)