Skip to contentSkip to conversation

CBUS: various cleanups

PATCH New Komal Shah 1 participant 1 message Mar 9, 2006

lore
Share & tools
lore

Komal Shah

author
#0 lore raw

PATCH 1/1 CBUS: various cleanups

Tony/Juha/Amit,

Attached patch is a first attempt to cleanup files under drivers/cbus directory with

o kmalloc + memset(0) -> kzalloc
o device_driver to platform_driver conversion madness :)

And few doubts after reading the code...!!!. Changes builds for N770. But unable to test it as *not* having access to n770.

cbus/retu-wdt.c
---------------

static int retu_modify_counter(unsigned int new)

{
        int ret = 0;

        if (new < RETU_WDT_MIN_TIMER || new > RETU_WDT_MAX_TIMER)
                return -EINVAL;

Why checking for < 0, for 'unsigned int new' ?

cbus/tahvo-usb.c
----------------
Please check the changes I made in this file, as I got confused, and may be done in-correct platform_driver related modifications.

static int omap_otg_remove(struct platform_device *pdev)

{
        tahvo_otg_dev = NULL;
        free_irq(tahvo_otg_dev->resource[1].start, &tahvo_usb_device);

Will free_irq will work with NULL tahvo_otg_dev?

tahvo_usb_probe function is not deleting sysfs files if otg_set_transceiver fails. Please check.

---Komal Shah
http://komalshah.blogspot.com/

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

drivers/cbus/cbus.c +1 -3
index eff38be..081c647 100644
@@ -222,12 +222,10 @@ int __init cbus_bus_init(void)
 	struct cbus_host *chost;
 	int ret;
 
-	chost = kmalloc(sizeof (*chost), GFP_KERNEL);
+	chost = kzalloc(sizeof (*chost), GFP_KERNEL);
 	if (chost == NULL)
 		return -ENOMEM;
 
-	memset(chost, 0, sizeof (*chost));
-
 	spin_lock_init(&chost->lock);
 
 	cbus_config = omap_get_config(OMAP_TAG_CBUS, struct omap_cbus_config);
drivers/cbus/retu-pwrbutton.c +3 -1
index da8c14c..55ac190 100644
@@ -69,6 +69,8 @@ static void retubutton_irq(unsigned long
 	mod_timer(&pwrbtn_timer, jiffies + msecs_to_jiffies(PWRBTN_DELAY));
 }
 
+static char banner[] __initdata = KERN_INFO "Retu power button driver initialized\n";
+
 /**
  * Init function.
  * Allocates interrupt for power button and registers itself to input layer.
@@ -77,7 +79,7 @@ static int __init retubutton_init(void)
 {
 	int irq;
 
-	printk(KERN_INFO "Retu power button driver initialized\n");
+	printk(banner);
 	irq = RETU_INT_PWR;
 
 	init_timer(&pwrbtn_timer);
drivers/cbus/retu-rtc.c +25 -24

115 lines not on this page · raw message

drivers/cbus/retu-user.c +2 -3
index 69d1be9..9454760 100644
@@ -372,12 +372,11 @@ int retu_user_init(void)
 	struct retu_irq *irq;
 	int res, i;
 
-	irq = kmalloc(sizeof(*irq) * RETU_MAX_IRQ_BUF_LEN, GFP_KERNEL);
+	irq = kzalloc(sizeof(*irq) * RETU_MAX_IRQ_BUF_LEN, GFP_KERNEL);
 	if (irq == NULL) {
-		printk(KERN_ERR PFX "kmalloc failed\n");
+		printk(KERN_ERR PFX "kzalloc failed\n");
 		return -ENOMEM;
 	}
-	memset(irq, 0, sizeof(*irq) * RETU_MAX_IRQ_BUF_LEN);
 	for (i = 0; i < RETU_MAX_IRQ_BUF_LEN; i++)
 		list_add(&irq[i].node, &retu_irqs_reserve);
 
drivers/cbus/retu-wdt.c +19 -16
index 9739907..629affc 100644
@@ -103,29 +103,29 @@ static DEVICE_ATTR(period, S_IRUGO | S_I
                    retu_wdt_period_store);
 static DEVICE_ATTR(counter, S_IRUGO, retu_wdt_counter_show, NULL);
 
-static int __devinit retu_wdt_probe(struct device *dev)
+static int __devinit retu_wdt_probe(struct platform_device *pdev)
 {
 	int ret;
 
-	ret = device_create_file(dev, &dev_attr_period);
+	ret = device_create_file(&pdev->dev, &dev_attr_period);
 	if (ret) {
 		printk(KERN_ERR "retu_wdt_probe: Error creating sys device file: period\n");
 		return ret;
 	}
 
-	ret = device_create_file(dev, &dev_attr_counter);
+	ret = device_create_file(&pdev->dev, &dev_attr_counter);
 	if (ret) {
-		device_remove_file(dev, &dev_attr_period);
+		device_remove_file(&pdev->dev, &dev_attr_period);
 		printk(KERN_ERR "retu_wdt_probe: Error creating sys device file: counter\n");
 	}
 
 	return ret;
 }
 
-static int __devexit retu_wdt_remove(struct device *dev)
+static int __devexit retu_wdt_remove(struct platform_device *pdev)
 {
-	device_remove_file(dev, &dev_attr_period);
-	device_remove_file(dev, &dev_attr_counter);
+	device_remove_file(&pdev->dev, &dev_attr_period);
+	device_remove_file(&pdev->dev, &dev_attr_counter);
 	return 0;
 }
 
@@ -142,20 +142,23 @@ static struct platform_device retu_wdt_d
 	},
 };
 
-static struct device_driver retu_wdt_driver = {
-	.name = "retu-watchdog",
-	.bus = &platform_bus_type,
-	.probe = retu_wdt_probe,
-	.remove = __devexit_p(retu_wdt_remove),
+static struct platform_driver retu_wdt_driver = {
+	.probe 		= retu_wdt_probe,
+	.remove 	= __devexit_p(retu_wdt_remove),
+	.driver 	= {
+		.name = "retu-watchdog",
+	},
 };
 
+static char banner[] __initdata = KERN_INFO "Retu watchdog driver initialized\n";
+
 static int __init retu_wdt_init(void)
 {
 	int ret;
 
 	init_completion(&retu_wdt_completion);
 
-	ret = driver_register(&retu_wdt_driver);
+	ret = platform_driver_register(&retu_wdt_driver);
 	if (ret)
 		return ret;
 
@@ -170,12 +173,12 @@ static int __init retu_wdt_init(void)
 		printk(KERN_INFO
 		       "retu_wdt_init: Intializing to default value\n");
 	}
-
-	printk(KERN_INFO "Retu watchdog driver initialized\n");
+	
+	printk(banner);
 	return ret;
 
 exit1:
-	driver_unregister(&retu_wdt_driver);
+	platform_driver_unregister(&retu_wdt_driver);
 	wait_for_completion(&retu_wdt_completion);
 
 	return ret;
drivers/cbus/retu.c +13 -10
index 87ab216..9c93f4e 100644
@@ -293,7 +293,7 @@ static void retu_power_off(void)
  * Probe for the Retu ASIC and allocate memory
  * for its device-struct if found
  */
-static int __devinit retu_probe(struct device *dev)
+static int __devinit retu_probe(struct platform_driver *pdev)
 {
 	const struct omap_em_asic_bb5_config * em_asic_config;
 	int rev, ret;
@@ -358,7 +358,7 @@ static int __devinit retu_probe(struct d
 	return 0;
 }
 
-static int retu_remove(struct device *dev)
+static int retu_remove(struct platform_driver *pdev)
 {
 #ifdef CONFIG_CBUS_RETU_USER
 	retu_user_cleanup();
@@ -377,11 +377,12 @@ static void retu_device_release(struct d
 	complete(&device_release);
 }
 
-static struct device_driver retu_driver = {
-	.name		= "retu",
-	.bus		= &platform_bus_type,
+static struct platform_driver retu_driver = {
 	.probe		= retu_probe,
 	.remove		= retu_remove,
+	.driver		= {
+		.name	= "retu",
+	},
 };
 
 static struct platform_device retu_device = {
@@ -392,6 +393,8 @@ static struct platform_device retu_devic
 	}
 };
 
+static char banner[] __initdata = KERN_INFO "Retu/Vilma driver initialising\n";
+
 /**
  * retu_init - initialise Retu driver
  *
@@ -401,15 +404,15 @@ static int __init retu_init(void)
 {
 	int ret = 0;
 
-	printk(KERN_INFO "Retu/Vilma driver initialising\n");
-
+	printk(banner);
+	
 	init_completion(&device_release);
 
-	if ((ret = driver_register(&retu_driver)) < 0)
+	if ((ret = platform_driver_register(&retu_driver)) < 0)
 		return ret;
 
 	if ((ret = platform_device_register(&retu_device)) < 0) {
-		driver_unregister(&retu_driver);
+		platform_driver_unregister(&retu_driver);
 		return ret;
 	}
 	return 0;
@@ -421,7 +424,7 @@ static int __init retu_init(void)
 static void __exit retu_exit(void)
 {
 	platform_device_unregister(&retu_device);
-	driver_unregister(&retu_driver);
+	platform_driver_unregister(&retu_driver);
 	wait_for_completion(&device_release);
 }
 
drivers/cbus/tahvo-usb.c +29 -26

146 lines not on this page · raw message

drivers/cbus/tahvo-user.c +2 -3
index 7e6f770..86c0145 100644
@@ -353,12 +353,11 @@ int tahvo_user_init(void)
 	struct tahvo_irq *irq;
 	int res, i;
 
-	irq = kmalloc(sizeof(*irq) * TAHVO_MAX_IRQ_BUF_LEN, GFP_KERNEL);
+	irq = kzalloc(sizeof(*irq) * TAHVO_MAX_IRQ_BUF_LEN, GFP_KERNEL);
 	if (irq == NULL) {
-		printk(KERN_ERR PFX "kmalloc failed\n");
+		printk(KERN_ERR PFX "kzalloc failed\n");
 		return -ENOMEM;
 	}
-	memset(irq, 0, sizeof(*irq) * TAHVO_MAX_IRQ_BUF_LEN);
 	for (i = 0; i < TAHVO_MAX_IRQ_BUF_LEN; i++)
 		list_add(&irq[i].node, &tahvo_irqs_reserve);
 
drivers/cbus/tahvo.c +9 -8
index 6693a74..9a98c68 100644
@@ -266,7 +266,7 @@ void tahvo_free_irq(int id)
  * Probe for the Tahvo ASIC and allocate memory
  * for its device-struct if found
  */
-static int __devinit tahvo_probe(struct device *dev)
+static int __devinit tahvo_probe(struct platform_device *pdev)
 {
 	const struct omap_em_asic_bb5_config * em_asic_config;
 	int rev, id, ret;
@@ -335,7 +335,7 @@ static int __devinit tahvo_probe(struct 
 	return 0;
 }
 
-static int tahvo_remove(struct device *dev)
+static int tahvo_remove(struct platform_device *pdev)
 {
 #ifdef CONFIG_CBUS_TAHVO_USER
 	tahvo_user_cleanup();
@@ -354,11 +354,12 @@ static void tahvo_device_release(struct 
 	complete(&device_release);
 }
 
-static struct device_driver tahvo_driver = {
-	.name		= "tahvo",
-	.bus		= &platform_bus_type,
+static struct platform_driver tahvo_driver = {
 	.probe		= tahvo_probe,
 	.remove		= tahvo_remove,
+	.driver		= {
+		.name	= "tahvo",
+	},
 };
 
 static struct platform_device tahvo_device = {
@@ -382,11 +383,11 @@ static int __init tahvo_init(void)
 
 	init_completion(&device_release);
 
-	if ((ret = driver_register(&tahvo_driver)) < 0)
+	if ((ret = platform_driver_register(&tahvo_driver)) < 0)
 		return ret;
 
 	if ((ret = platform_device_register(&tahvo_device)) < 0) {
-		driver_unregister(&tahvo_driver);
+		platform_driver_unregister(&tahvo_driver);
 		return ret;
 	}
 	return 0;
@@ -398,7 +399,7 @@ static int __init tahvo_init(void)
 static void __exit tahvo_exit(void)
 {
 	platform_device_unregister(&tahvo_device);
-	driver_unregister(&tahvo_driver);
+	platform_driver_unregister(&tahvo_driver);
 	wait_for_completion(&device_release);
 }
 
drivers/cbus/user_retu_tahvo.h +0 -0