Commit 49a6cbe1cd8a72451d9d6ab5b1e163f17c1bbee3

Authored by Jeff Garzik
Committed by Linus Torvalds
1 parent 69b2186c5f

[PATCH] drivers/mca: handle sysfs errors

Also includes a kmalloc->kzalloc cleanup.

Signed-off-by: Jeff Garzik <jeff@garzik.org>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 1 changed file with 21 additions and 7 deletions Side-by-side Diff

drivers/mca/mca-bus.c
... ... @@ -100,6 +100,7 @@
100 100 int __init mca_register_device(int bus, struct mca_device *mca_dev)
101 101 {
102 102 struct mca_bus *mca_bus = mca_root_busses[bus];
  103 + int rc;
103 104  
104 105 mca_dev->dev.parent = &mca_bus->dev;
105 106 mca_dev->dev.bus = &mca_bus_type;
106 107  
107 108  
... ... @@ -108,13 +109,23 @@
108 109 mca_dev->dev.dma_mask = &mca_dev->dma_mask;
109 110 mca_dev->dev.coherent_dma_mask = mca_dev->dma_mask;
110 111  
111   - if (device_register(&mca_dev->dev))
112   - return 0;
  112 + rc = device_register(&mca_dev->dev);
  113 + if (rc)
  114 + goto err_out;
113 115  
114   - device_create_file(&mca_dev->dev, &dev_attr_id);
115   - device_create_file(&mca_dev->dev, &dev_attr_pos);
  116 + rc = device_create_file(&mca_dev->dev, &dev_attr_id);
  117 + if (rc) goto err_out_devreg;
  118 + rc = device_create_file(&mca_dev->dev, &dev_attr_pos);
  119 + if (rc) goto err_out_id;
116 120  
117 121 return 1;
  122 +
  123 +err_out_id:
  124 + device_remove_file(&mca_dev->dev, &dev_attr_id);
  125 +err_out_devreg:
  126 + device_unregister(&mca_dev->dev);
  127 +err_out:
  128 + return 0;
118 129 }
119 130  
120 131 /* */
121 132  
122 133  
... ... @@ -130,13 +141,16 @@
130 141 return NULL;
131 142 }
132 143  
133   - mca_bus = kmalloc(sizeof(struct mca_bus), GFP_KERNEL);
  144 + mca_bus = kzalloc(sizeof(struct mca_bus), GFP_KERNEL);
134 145 if (!mca_bus)
135 146 return NULL;
136   - memset(mca_bus, 0, sizeof(struct mca_bus));
  147 +
137 148 sprintf(mca_bus->dev.bus_id,"mca%d",bus);
138 149 sprintf(mca_bus->name,"Host %s MCA Bridge", bus ? "Secondary" : "Primary");
139   - device_register(&mca_bus->dev);
  150 + if (device_register(&mca_bus->dev)) {
  151 + kfree(mca_bus);
  152 + return NULL;
  153 + }
140 154  
141 155 mca_root_busses[bus] = mca_bus;
142 156