diff options
author | Corey Minyard <cminyard@mvista.com> | 2014-10-10 22:54:03 -0400 |
---|---|---|
committer | Corey Minyard <cminyard@mvista.com> | 2014-12-11 16:04:04 -0500 |
commit | 16639eb08a6947bef8f4d78e22b6010ba4c3cb90 (patch) | |
tree | 853f81ee94a18723e7880bff038b5ed21bcba55f /drivers/char/ipmi/ipmi_msghandler.c | |
parent | 7e50387bceda4d5542e4ba87097f69071b425fe5 (diff) |
ipmi: clean up the device handling for the bmc device
Embed the platform device in the bmc device instead of externally
allocating it, use more proper form for creating the device
attributes, and other general cleanups.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
Diffstat (limited to 'drivers/char/ipmi/ipmi_msghandler.c')
-rw-r--r-- | drivers/char/ipmi/ipmi_msghandler.c | 285 |
1 files changed, 92 insertions, 193 deletions
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index e5d7c0b6fe3d..4539afa5b7f2 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c | |||
@@ -191,12 +191,12 @@ struct ipmi_proc_entry { | |||
191 | #endif | 191 | #endif |
192 | 192 | ||
193 | struct bmc_device { | 193 | struct bmc_device { |
194 | struct platform_device *dev; | 194 | struct platform_device pdev; |
195 | struct ipmi_device_id id; | 195 | struct ipmi_device_id id; |
196 | unsigned char guid[16]; | 196 | unsigned char guid[16]; |
197 | int guid_set; | 197 | int guid_set; |
198 | 198 | char name[16]; | |
199 | struct kref refcount; | 199 | struct kref usecount; |
200 | 200 | ||
201 | /* bmc device attributes */ | 201 | /* bmc device attributes */ |
202 | struct device_attribute device_id_attr; | 202 | struct device_attribute device_id_attr; |
@@ -210,6 +210,7 @@ struct bmc_device { | |||
210 | struct device_attribute guid_attr; | 210 | struct device_attribute guid_attr; |
211 | struct device_attribute aux_firmware_rev_attr; | 211 | struct device_attribute aux_firmware_rev_attr; |
212 | }; | 212 | }; |
213 | #define to_bmc_device(x) container_of((x), struct bmc_device, pdev.dev) | ||
213 | 214 | ||
214 | /* | 215 | /* |
215 | * Various statistics for IPMI, these index stats[] in the ipmi_smi | 216 | * Various statistics for IPMI, these index stats[] in the ipmi_smi |
@@ -2165,7 +2166,7 @@ static void remove_proc_entries(ipmi_smi_t smi) | |||
2165 | static int __find_bmc_guid(struct device *dev, void *data) | 2166 | static int __find_bmc_guid(struct device *dev, void *data) |
2166 | { | 2167 | { |
2167 | unsigned char *id = data; | 2168 | unsigned char *id = data; |
2168 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2169 | struct bmc_device *bmc = to_bmc_device(dev); |
2169 | return memcmp(bmc->guid, id, 16) == 0; | 2170 | return memcmp(bmc->guid, id, 16) == 0; |
2170 | } | 2171 | } |
2171 | 2172 | ||
@@ -2176,7 +2177,7 @@ static struct bmc_device *ipmi_find_bmc_guid(struct device_driver *drv, | |||
2176 | 2177 | ||
2177 | dev = driver_find_device(drv, NULL, guid, __find_bmc_guid); | 2178 | dev = driver_find_device(drv, NULL, guid, __find_bmc_guid); |
2178 | if (dev) | 2179 | if (dev) |
2179 | return dev_get_drvdata(dev); | 2180 | return to_bmc_device(dev); |
2180 | else | 2181 | else |
2181 | return NULL; | 2182 | return NULL; |
2182 | } | 2183 | } |
@@ -2189,7 +2190,7 @@ struct prod_dev_id { | |||
2189 | static int __find_bmc_prod_dev_id(struct device *dev, void *data) | 2190 | static int __find_bmc_prod_dev_id(struct device *dev, void *data) |
2190 | { | 2191 | { |
2191 | struct prod_dev_id *id = data; | 2192 | struct prod_dev_id *id = data; |
2192 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2193 | struct bmc_device *bmc = to_bmc_device(dev); |
2193 | 2194 | ||
2194 | return (bmc->id.product_id == id->product_id | 2195 | return (bmc->id.product_id == id->product_id |
2195 | && bmc->id.device_id == id->device_id); | 2196 | && bmc->id.device_id == id->device_id); |
@@ -2207,7 +2208,7 @@ static struct bmc_device *ipmi_find_bmc_prod_dev_id( | |||
2207 | 2208 | ||
2208 | dev = driver_find_device(drv, NULL, &id, __find_bmc_prod_dev_id); | 2209 | dev = driver_find_device(drv, NULL, &id, __find_bmc_prod_dev_id); |
2209 | if (dev) | 2210 | if (dev) |
2210 | return dev_get_drvdata(dev); | 2211 | return to_bmc_device(dev); |
2211 | else | 2212 | else |
2212 | return NULL; | 2213 | return NULL; |
2213 | } | 2214 | } |
@@ -2216,84 +2217,92 @@ static ssize_t device_id_show(struct device *dev, | |||
2216 | struct device_attribute *attr, | 2217 | struct device_attribute *attr, |
2217 | char *buf) | 2218 | char *buf) |
2218 | { | 2219 | { |
2219 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2220 | struct bmc_device *bmc = to_bmc_device(dev); |
2220 | 2221 | ||
2221 | return snprintf(buf, 10, "%u\n", bmc->id.device_id); | 2222 | return snprintf(buf, 10, "%u\n", bmc->id.device_id); |
2222 | } | 2223 | } |
2224 | DEVICE_ATTR(device_id, S_IRUGO, device_id_show, NULL); | ||
2223 | 2225 | ||
2224 | static ssize_t provides_dev_sdrs_show(struct device *dev, | 2226 | static ssize_t provides_device_sdrs_show(struct device *dev, |
2225 | struct device_attribute *attr, | 2227 | struct device_attribute *attr, |
2226 | char *buf) | 2228 | char *buf) |
2227 | { | 2229 | { |
2228 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2230 | struct bmc_device *bmc = to_bmc_device(dev); |
2229 | 2231 | ||
2230 | return snprintf(buf, 10, "%u\n", | 2232 | return snprintf(buf, 10, "%u\n", |
2231 | (bmc->id.device_revision & 0x80) >> 7); | 2233 | (bmc->id.device_revision & 0x80) >> 7); |
2232 | } | 2234 | } |
2235 | DEVICE_ATTR(provides_device_sdrs, S_IRUGO, provides_device_sdrs_show, NULL); | ||
2233 | 2236 | ||
2234 | static ssize_t revision_show(struct device *dev, struct device_attribute *attr, | 2237 | static ssize_t revision_show(struct device *dev, struct device_attribute *attr, |
2235 | char *buf) | 2238 | char *buf) |
2236 | { | 2239 | { |
2237 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2240 | struct bmc_device *bmc = to_bmc_device(dev); |
2238 | 2241 | ||
2239 | return snprintf(buf, 20, "%u\n", | 2242 | return snprintf(buf, 20, "%u\n", |
2240 | bmc->id.device_revision & 0x0F); | 2243 | bmc->id.device_revision & 0x0F); |
2241 | } | 2244 | } |
2245 | DEVICE_ATTR(revision, S_IRUGO, revision_show, NULL); | ||
2242 | 2246 | ||
2243 | static ssize_t firmware_rev_show(struct device *dev, | 2247 | static ssize_t firmware_revision_show(struct device *dev, |
2244 | struct device_attribute *attr, | 2248 | struct device_attribute *attr, |
2245 | char *buf) | 2249 | char *buf) |
2246 | { | 2250 | { |
2247 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2251 | struct bmc_device *bmc = to_bmc_device(dev); |
2248 | 2252 | ||
2249 | return snprintf(buf, 20, "%u.%x\n", bmc->id.firmware_revision_1, | 2253 | return snprintf(buf, 20, "%u.%x\n", bmc->id.firmware_revision_1, |
2250 | bmc->id.firmware_revision_2); | 2254 | bmc->id.firmware_revision_2); |
2251 | } | 2255 | } |
2256 | DEVICE_ATTR(firmware_revision, S_IRUGO, firmware_revision_show, NULL); | ||
2252 | 2257 | ||
2253 | static ssize_t ipmi_version_show(struct device *dev, | 2258 | static ssize_t ipmi_version_show(struct device *dev, |
2254 | struct device_attribute *attr, | 2259 | struct device_attribute *attr, |
2255 | char *buf) | 2260 | char *buf) |
2256 | { | 2261 | { |
2257 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2262 | struct bmc_device *bmc = to_bmc_device(dev); |
2258 | 2263 | ||
2259 | return snprintf(buf, 20, "%u.%u\n", | 2264 | return snprintf(buf, 20, "%u.%u\n", |
2260 | ipmi_version_major(&bmc->id), | 2265 | ipmi_version_major(&bmc->id), |
2261 | ipmi_version_minor(&bmc->id)); | 2266 | ipmi_version_minor(&bmc->id)); |
2262 | } | 2267 | } |
2268 | DEVICE_ATTR(ipmi_version, S_IRUGO, ipmi_version_show, NULL); | ||
2263 | 2269 | ||
2264 | static ssize_t add_dev_support_show(struct device *dev, | 2270 | static ssize_t add_dev_support_show(struct device *dev, |
2265 | struct device_attribute *attr, | 2271 | struct device_attribute *attr, |
2266 | char *buf) | 2272 | char *buf) |
2267 | { | 2273 | { |
2268 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2274 | struct bmc_device *bmc = to_bmc_device(dev); |
2269 | 2275 | ||
2270 | return snprintf(buf, 10, "0x%02x\n", | 2276 | return snprintf(buf, 10, "0x%02x\n", |
2271 | bmc->id.additional_device_support); | 2277 | bmc->id.additional_device_support); |
2272 | } | 2278 | } |
2279 | DEVICE_ATTR(additional_device_support, S_IRUGO, add_dev_support_show, NULL); | ||
2273 | 2280 | ||
2274 | static ssize_t manufacturer_id_show(struct device *dev, | 2281 | static ssize_t manufacturer_id_show(struct device *dev, |
2275 | struct device_attribute *attr, | 2282 | struct device_attribute *attr, |
2276 | char *buf) | 2283 | char *buf) |
2277 | { | 2284 | { |
2278 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2285 | struct bmc_device *bmc = to_bmc_device(dev); |
2279 | 2286 | ||
2280 | return snprintf(buf, 20, "0x%6.6x\n", bmc->id.manufacturer_id); | 2287 | return snprintf(buf, 20, "0x%6.6x\n", bmc->id.manufacturer_id); |
2281 | } | 2288 | } |
2289 | DEVICE_ATTR(manufacturer_id, S_IRUGO, manufacturer_id_show, NULL); | ||
2282 | 2290 | ||
2283 | static ssize_t product_id_show(struct device *dev, | 2291 | static ssize_t product_id_show(struct device *dev, |
2284 | struct device_attribute *attr, | 2292 | struct device_attribute *attr, |
2285 | char *buf) | 2293 | char *buf) |
2286 | { | 2294 | { |
2287 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2295 | struct bmc_device *bmc = to_bmc_device(dev); |
2288 | 2296 | ||
2289 | return snprintf(buf, 10, "0x%4.4x\n", bmc->id.product_id); | 2297 | return snprintf(buf, 10, "0x%4.4x\n", bmc->id.product_id); |
2290 | } | 2298 | } |
2299 | DEVICE_ATTR(product_id, S_IRUGO, product_id_show, NULL); | ||
2291 | 2300 | ||
2292 | static ssize_t aux_firmware_rev_show(struct device *dev, | 2301 | static ssize_t aux_firmware_rev_show(struct device *dev, |
2293 | struct device_attribute *attr, | 2302 | struct device_attribute *attr, |
2294 | char *buf) | 2303 | char *buf) |
2295 | { | 2304 | { |
2296 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2305 | struct bmc_device *bmc = to_bmc_device(dev); |
2297 | 2306 | ||
2298 | return snprintf(buf, 21, "0x%02x 0x%02x 0x%02x 0x%02x\n", | 2307 | return snprintf(buf, 21, "0x%02x 0x%02x 0x%02x 0x%02x\n", |
2299 | bmc->id.aux_firmware_revision[3], | 2308 | bmc->id.aux_firmware_revision[3], |
@@ -2301,57 +2310,63 @@ static ssize_t aux_firmware_rev_show(struct device *dev, | |||
2301 | bmc->id.aux_firmware_revision[1], | 2310 | bmc->id.aux_firmware_revision[1], |
2302 | bmc->id.aux_firmware_revision[0]); | 2311 | bmc->id.aux_firmware_revision[0]); |
2303 | } | 2312 | } |
2313 | DEVICE_ATTR(aux_firmware_revision, S_IRUGO, aux_firmware_rev_show, NULL); | ||
2304 | 2314 | ||
2305 | static ssize_t guid_show(struct device *dev, struct device_attribute *attr, | 2315 | static ssize_t guid_show(struct device *dev, struct device_attribute *attr, |
2306 | char *buf) | 2316 | char *buf) |
2307 | { | 2317 | { |
2308 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2318 | struct bmc_device *bmc = to_bmc_device(dev); |
2309 | 2319 | ||
2310 | return snprintf(buf, 100, "%Lx%Lx\n", | 2320 | return snprintf(buf, 100, "%Lx%Lx\n", |
2311 | (long long) bmc->guid[0], | 2321 | (long long) bmc->guid[0], |
2312 | (long long) bmc->guid[8]); | 2322 | (long long) bmc->guid[8]); |
2313 | } | 2323 | } |
2324 | DEVICE_ATTR(guid, S_IRUGO, guid_show, NULL); | ||
2325 | |||
2326 | static struct attribute *bmc_dev_attrs[] = { | ||
2327 | &dev_attr_device_id.attr, | ||
2328 | &dev_attr_provides_device_sdrs.attr, | ||
2329 | &dev_attr_revision.attr, | ||
2330 | &dev_attr_firmware_revision.attr, | ||
2331 | &dev_attr_ipmi_version.attr, | ||
2332 | &dev_attr_additional_device_support.attr, | ||
2333 | &dev_attr_manufacturer_id.attr, | ||
2334 | &dev_attr_product_id.attr, | ||
2335 | NULL | ||
2336 | }; | ||
2314 | 2337 | ||
2315 | static void remove_files(struct bmc_device *bmc) | 2338 | static struct attribute_group bmc_dev_attr_group = { |
2316 | { | 2339 | .attrs = bmc_dev_attrs, |
2317 | if (!bmc->dev) | 2340 | }; |
2318 | return; | ||
2319 | 2341 | ||
2320 | device_remove_file(&bmc->dev->dev, | 2342 | static const struct attribute_group *bmc_dev_attr_groups[] = { |
2321 | &bmc->device_id_attr); | 2343 | &bmc_dev_attr_group, |
2322 | device_remove_file(&bmc->dev->dev, | 2344 | NULL |
2323 | &bmc->provides_dev_sdrs_attr); | 2345 | }; |
2324 | device_remove_file(&bmc->dev->dev, | ||
2325 | &bmc->revision_attr); | ||
2326 | device_remove_file(&bmc->dev->dev, | ||
2327 | &bmc->firmware_rev_attr); | ||
2328 | device_remove_file(&bmc->dev->dev, | ||
2329 | &bmc->version_attr); | ||
2330 | device_remove_file(&bmc->dev->dev, | ||
2331 | &bmc->add_dev_support_attr); | ||
2332 | device_remove_file(&bmc->dev->dev, | ||
2333 | &bmc->manufacturer_id_attr); | ||
2334 | device_remove_file(&bmc->dev->dev, | ||
2335 | &bmc->product_id_attr); | ||
2336 | 2346 | ||
2337 | if (bmc->id.aux_firmware_revision_set) | 2347 | static struct device_type bmc_device_type = { |
2338 | device_remove_file(&bmc->dev->dev, | 2348 | .groups = bmc_dev_attr_groups, |
2339 | &bmc->aux_firmware_rev_attr); | 2349 | }; |
2340 | if (bmc->guid_set) | 2350 | |
2341 | device_remove_file(&bmc->dev->dev, | 2351 | static void |
2342 | &bmc->guid_attr); | 2352 | release_bmc_device(struct device *dev) |
2353 | { | ||
2354 | kfree(to_bmc_device(dev)); | ||
2343 | } | 2355 | } |
2344 | 2356 | ||
2345 | static void | 2357 | static void |
2346 | cleanup_bmc_device(struct kref *ref) | 2358 | cleanup_bmc_device(struct kref *ref) |
2347 | { | 2359 | { |
2348 | struct bmc_device *bmc; | 2360 | struct bmc_device *bmc = container_of(ref, struct bmc_device, usecount); |
2349 | 2361 | ||
2350 | bmc = container_of(ref, struct bmc_device, refcount); | 2362 | if (bmc->id.aux_firmware_revision_set) |
2363 | device_remove_file(&bmc->pdev.dev, | ||
2364 | &bmc->aux_firmware_rev_attr); | ||
2365 | if (bmc->guid_set) | ||
2366 | device_remove_file(&bmc->pdev.dev, | ||
2367 | &bmc->guid_attr); | ||
2351 | 2368 | ||
2352 | remove_files(bmc); | 2369 | platform_device_unregister(&bmc->pdev); |
2353 | platform_device_unregister(bmc->dev); | ||
2354 | kfree(bmc); | ||
2355 | } | 2370 | } |
2356 | 2371 | ||
2357 | static void ipmi_bmc_unregister(ipmi_smi_t intf) | 2372 | static void ipmi_bmc_unregister(ipmi_smi_t intf) |
@@ -2364,111 +2379,29 @@ static void ipmi_bmc_unregister(ipmi_smi_t intf) | |||
2364 | intf->sysfs_name = NULL; | 2379 | intf->sysfs_name = NULL; |
2365 | } | 2380 | } |
2366 | if (intf->my_dev_name) { | 2381 | if (intf->my_dev_name) { |
2367 | sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name); | 2382 | sysfs_remove_link(&bmc->pdev.dev.kobj, intf->my_dev_name); |
2368 | kfree(intf->my_dev_name); | 2383 | kfree(intf->my_dev_name); |
2369 | intf->my_dev_name = NULL; | 2384 | intf->my_dev_name = NULL; |
2370 | } | 2385 | } |
2371 | 2386 | ||
2372 | mutex_lock(&ipmidriver_mutex); | 2387 | mutex_lock(&ipmidriver_mutex); |
2373 | kref_put(&bmc->refcount, cleanup_bmc_device); | 2388 | kref_put(&bmc->usecount, cleanup_bmc_device); |
2374 | intf->bmc = NULL; | 2389 | intf->bmc = NULL; |
2375 | mutex_unlock(&ipmidriver_mutex); | 2390 | mutex_unlock(&ipmidriver_mutex); |
2376 | } | 2391 | } |
2377 | 2392 | ||
2378 | static int create_files(struct bmc_device *bmc) | 2393 | static int create_bmc_files(struct bmc_device *bmc) |
2379 | { | 2394 | { |
2380 | int err; | 2395 | int err; |
2381 | 2396 | ||
2382 | bmc->device_id_attr.attr.name = "device_id"; | ||
2383 | bmc->device_id_attr.attr.mode = S_IRUGO; | ||
2384 | bmc->device_id_attr.show = device_id_show; | ||
2385 | sysfs_attr_init(&bmc->device_id_attr.attr); | ||
2386 | |||
2387 | bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; | ||
2388 | bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; | ||
2389 | bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show; | ||
2390 | sysfs_attr_init(&bmc->provides_dev_sdrs_attr.attr); | ||
2391 | |||
2392 | bmc->revision_attr.attr.name = "revision"; | ||
2393 | bmc->revision_attr.attr.mode = S_IRUGO; | ||
2394 | bmc->revision_attr.show = revision_show; | ||
2395 | sysfs_attr_init(&bmc->revision_attr.attr); | ||
2396 | |||
2397 | bmc->firmware_rev_attr.attr.name = "firmware_revision"; | ||
2398 | bmc->firmware_rev_attr.attr.mode = S_IRUGO; | ||
2399 | bmc->firmware_rev_attr.show = firmware_rev_show; | ||
2400 | sysfs_attr_init(&bmc->firmware_rev_attr.attr); | ||
2401 | |||
2402 | bmc->version_attr.attr.name = "ipmi_version"; | ||
2403 | bmc->version_attr.attr.mode = S_IRUGO; | ||
2404 | bmc->version_attr.show = ipmi_version_show; | ||
2405 | sysfs_attr_init(&bmc->version_attr.attr); | ||
2406 | |||
2407 | bmc->add_dev_support_attr.attr.name = "additional_device_support"; | ||
2408 | bmc->add_dev_support_attr.attr.mode = S_IRUGO; | ||
2409 | bmc->add_dev_support_attr.show = add_dev_support_show; | ||
2410 | sysfs_attr_init(&bmc->add_dev_support_attr.attr); | ||
2411 | |||
2412 | bmc->manufacturer_id_attr.attr.name = "manufacturer_id"; | ||
2413 | bmc->manufacturer_id_attr.attr.mode = S_IRUGO; | ||
2414 | bmc->manufacturer_id_attr.show = manufacturer_id_show; | ||
2415 | sysfs_attr_init(&bmc->manufacturer_id_attr.attr); | ||
2416 | |||
2417 | bmc->product_id_attr.attr.name = "product_id"; | ||
2418 | bmc->product_id_attr.attr.mode = S_IRUGO; | ||
2419 | bmc->product_id_attr.show = product_id_show; | ||
2420 | sysfs_attr_init(&bmc->product_id_attr.attr); | ||
2421 | |||
2422 | bmc->guid_attr.attr.name = "guid"; | ||
2423 | bmc->guid_attr.attr.mode = S_IRUGO; | ||
2424 | bmc->guid_attr.show = guid_show; | ||
2425 | sysfs_attr_init(&bmc->guid_attr.attr); | ||
2426 | |||
2427 | bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision"; | ||
2428 | bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO; | ||
2429 | bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show; | ||
2430 | sysfs_attr_init(&bmc->aux_firmware_rev_attr.attr); | ||
2431 | |||
2432 | err = device_create_file(&bmc->dev->dev, | ||
2433 | &bmc->device_id_attr); | ||
2434 | if (err) | ||
2435 | goto out; | ||
2436 | err = device_create_file(&bmc->dev->dev, | ||
2437 | &bmc->provides_dev_sdrs_attr); | ||
2438 | if (err) | ||
2439 | goto out_devid; | ||
2440 | err = device_create_file(&bmc->dev->dev, | ||
2441 | &bmc->revision_attr); | ||
2442 | if (err) | ||
2443 | goto out_sdrs; | ||
2444 | err = device_create_file(&bmc->dev->dev, | ||
2445 | &bmc->firmware_rev_attr); | ||
2446 | if (err) | ||
2447 | goto out_rev; | ||
2448 | err = device_create_file(&bmc->dev->dev, | ||
2449 | &bmc->version_attr); | ||
2450 | if (err) | ||
2451 | goto out_firm; | ||
2452 | err = device_create_file(&bmc->dev->dev, | ||
2453 | &bmc->add_dev_support_attr); | ||
2454 | if (err) | ||
2455 | goto out_version; | ||
2456 | err = device_create_file(&bmc->dev->dev, | ||
2457 | &bmc->manufacturer_id_attr); | ||
2458 | if (err) | ||
2459 | goto out_add_dev; | ||
2460 | err = device_create_file(&bmc->dev->dev, | ||
2461 | &bmc->product_id_attr); | ||
2462 | if (err) | ||
2463 | goto out_manu; | ||
2464 | if (bmc->id.aux_firmware_revision_set) { | 2397 | if (bmc->id.aux_firmware_revision_set) { |
2465 | err = device_create_file(&bmc->dev->dev, | 2398 | err = device_create_file(&bmc->pdev.dev, |
2466 | &bmc->aux_firmware_rev_attr); | 2399 | &bmc->aux_firmware_rev_attr); |
2467 | if (err) | 2400 | if (err) |
2468 | goto out_prod_id; | 2401 | goto out; |
2469 | } | 2402 | } |
2470 | if (bmc->guid_set) { | 2403 | if (bmc->guid_set) { |
2471 | err = device_create_file(&bmc->dev->dev, | 2404 | err = device_create_file(&bmc->pdev.dev, |
2472 | &bmc->guid_attr); | 2405 | &bmc->guid_attr); |
2473 | if (err) | 2406 | if (err) |
2474 | goto out_aux_firm; | 2407 | goto out_aux_firm; |
@@ -2478,32 +2411,8 @@ static int create_files(struct bmc_device *bmc) | |||
2478 | 2411 | ||
2479 | out_aux_firm: | 2412 | out_aux_firm: |
2480 | if (bmc->id.aux_firmware_revision_set) | 2413 | if (bmc->id.aux_firmware_revision_set) |
2481 | device_remove_file(&bmc->dev->dev, | 2414 | device_remove_file(&bmc->pdev.dev, |
2482 | &bmc->aux_firmware_rev_attr); | 2415 | &bmc->aux_firmware_rev_attr); |
2483 | out_prod_id: | ||
2484 | device_remove_file(&bmc->dev->dev, | ||
2485 | &bmc->product_id_attr); | ||
2486 | out_manu: | ||
2487 | device_remove_file(&bmc->dev->dev, | ||
2488 | &bmc->manufacturer_id_attr); | ||
2489 | out_add_dev: | ||
2490 | device_remove_file(&bmc->dev->dev, | ||
2491 | &bmc->add_dev_support_attr); | ||
2492 | out_version: | ||
2493 | device_remove_file(&bmc->dev->dev, | ||
2494 | &bmc->version_attr); | ||
2495 | out_firm: | ||
2496 | device_remove_file(&bmc->dev->dev, | ||
2497 | &bmc->firmware_rev_attr); | ||
2498 | out_rev: | ||
2499 | device_remove_file(&bmc->dev->dev, | ||
2500 | &bmc->revision_attr); | ||
2501 | out_sdrs: | ||
2502 | device_remove_file(&bmc->dev->dev, | ||
2503 | &bmc->provides_dev_sdrs_attr); | ||
2504 | out_devid: | ||
2505 | device_remove_file(&bmc->dev->dev, | ||
2506 | &bmc->device_id_attr); | ||
2507 | out: | 2416 | out: |
2508 | return err; | 2417 | return err; |
2509 | } | 2418 | } |
@@ -2514,8 +2423,6 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, | |||
2514 | int rv; | 2423 | int rv; |
2515 | struct bmc_device *bmc = intf->bmc; | 2424 | struct bmc_device *bmc = intf->bmc; |
2516 | struct bmc_device *old_bmc; | 2425 | struct bmc_device *old_bmc; |
2517 | int size; | ||
2518 | char dummy[1]; | ||
2519 | 2426 | ||
2520 | mutex_lock(&ipmidriver_mutex); | 2427 | mutex_lock(&ipmidriver_mutex); |
2521 | 2428 | ||
@@ -2539,7 +2446,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, | |||
2539 | intf->bmc = old_bmc; | 2446 | intf->bmc = old_bmc; |
2540 | bmc = old_bmc; | 2447 | bmc = old_bmc; |
2541 | 2448 | ||
2542 | kref_get(&bmc->refcount); | 2449 | kref_get(&bmc->usecount); |
2543 | mutex_unlock(&ipmidriver_mutex); | 2450 | mutex_unlock(&ipmidriver_mutex); |
2544 | 2451 | ||
2545 | printk(KERN_INFO | 2452 | printk(KERN_INFO |
@@ -2549,12 +2456,12 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, | |||
2549 | bmc->id.product_id, | 2456 | bmc->id.product_id, |
2550 | bmc->id.device_id); | 2457 | bmc->id.device_id); |
2551 | } else { | 2458 | } else { |
2552 | char name[14]; | ||
2553 | unsigned char orig_dev_id = bmc->id.device_id; | 2459 | unsigned char orig_dev_id = bmc->id.device_id; |
2554 | int warn_printed = 0; | 2460 | int warn_printed = 0; |
2555 | 2461 | ||
2556 | snprintf(name, sizeof(name), | 2462 | snprintf(bmc->name, sizeof(bmc->name), |
2557 | "ipmi_bmc.%4.4x", bmc->id.product_id); | 2463 | "ipmi_bmc.%4.4x", bmc->id.product_id); |
2464 | bmc->pdev.name = bmc->name; | ||
2558 | 2465 | ||
2559 | while (ipmi_find_bmc_prod_dev_id(&ipmidriver.driver, | 2466 | while (ipmi_find_bmc_prod_dev_id(&ipmidriver.driver, |
2560 | bmc->id.product_id, | 2467 | bmc->id.product_id, |
@@ -2578,23 +2485,15 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, | |||
2578 | } | 2485 | } |
2579 | } | 2486 | } |
2580 | 2487 | ||
2581 | bmc->dev = platform_device_alloc(name, bmc->id.device_id); | 2488 | bmc->pdev.dev.driver = &ipmidriver.driver; |
2582 | if (!bmc->dev) { | 2489 | bmc->pdev.id = bmc->id.device_id; |
2583 | mutex_unlock(&ipmidriver_mutex); | 2490 | bmc->pdev.dev.release = release_bmc_device; |
2584 | printk(KERN_ERR | 2491 | bmc->pdev.dev.type = &bmc_device_type; |
2585 | "ipmi_msghandler:" | ||
2586 | " Unable to allocate platform device\n"); | ||
2587 | return -ENOMEM; | ||
2588 | } | ||
2589 | bmc->dev->dev.driver = &ipmidriver.driver; | ||
2590 | dev_set_drvdata(&bmc->dev->dev, bmc); | ||
2591 | kref_init(&bmc->refcount); | ||
2592 | 2492 | ||
2593 | rv = platform_device_add(bmc->dev); | 2493 | rv = platform_device_register(&bmc->pdev); |
2594 | mutex_unlock(&ipmidriver_mutex); | 2494 | mutex_unlock(&ipmidriver_mutex); |
2595 | if (rv) { | 2495 | if (rv) { |
2596 | platform_device_put(bmc->dev); | 2496 | put_device(&bmc->pdev.dev); |
2597 | bmc->dev = NULL; | ||
2598 | printk(KERN_ERR | 2497 | printk(KERN_ERR |
2599 | "ipmi_msghandler:" | 2498 | "ipmi_msghandler:" |
2600 | " Unable to register bmc device: %d\n", | 2499 | " Unable to register bmc device: %d\n", |
@@ -2606,10 +2505,12 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, | |||
2606 | return rv; | 2505 | return rv; |
2607 | } | 2506 | } |
2608 | 2507 | ||
2609 | rv = create_files(bmc); | 2508 | kref_init(&bmc->usecount); |
2509 | |||
2510 | rv = create_bmc_files(bmc); | ||
2610 | if (rv) { | 2511 | if (rv) { |
2611 | mutex_lock(&ipmidriver_mutex); | 2512 | mutex_lock(&ipmidriver_mutex); |
2612 | platform_device_unregister(bmc->dev); | 2513 | platform_device_unregister(&bmc->pdev); |
2613 | mutex_unlock(&ipmidriver_mutex); | 2514 | mutex_unlock(&ipmidriver_mutex); |
2614 | 2515 | ||
2615 | return rv; | 2516 | return rv; |
@@ -2636,7 +2537,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, | |||
2636 | } | 2537 | } |
2637 | 2538 | ||
2638 | rv = sysfs_create_link(&intf->si_dev->kobj, | 2539 | rv = sysfs_create_link(&intf->si_dev->kobj, |
2639 | &bmc->dev->dev.kobj, intf->sysfs_name); | 2540 | &bmc->pdev.dev.kobj, intf->sysfs_name); |
2640 | if (rv) { | 2541 | if (rv) { |
2641 | kfree(intf->sysfs_name); | 2542 | kfree(intf->sysfs_name); |
2642 | intf->sysfs_name = NULL; | 2543 | intf->sysfs_name = NULL; |
@@ -2646,8 +2547,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, | |||
2646 | goto out_err; | 2547 | goto out_err; |
2647 | } | 2548 | } |
2648 | 2549 | ||
2649 | size = snprintf(dummy, 0, "ipmi%d", ifnum); | 2550 | intf->my_dev_name = kasprintf(GFP_KERNEL, "ipmi%d", ifnum); |
2650 | intf->my_dev_name = kmalloc(size+1, GFP_KERNEL); | ||
2651 | if (!intf->my_dev_name) { | 2551 | if (!intf->my_dev_name) { |
2652 | kfree(intf->sysfs_name); | 2552 | kfree(intf->sysfs_name); |
2653 | intf->sysfs_name = NULL; | 2553 | intf->sysfs_name = NULL; |
@@ -2657,9 +2557,8 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, | |||
2657 | rv); | 2557 | rv); |
2658 | goto out_err; | 2558 | goto out_err; |
2659 | } | 2559 | } |
2660 | snprintf(intf->my_dev_name, size+1, "ipmi%d", ifnum); | ||
2661 | 2560 | ||
2662 | rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj, | 2561 | rv = sysfs_create_link(&bmc->pdev.dev.kobj, &intf->si_dev->kobj, |
2663 | intf->my_dev_name); | 2562 | intf->my_dev_name); |
2664 | if (rv) { | 2563 | if (rv) { |
2665 | kfree(intf->sysfs_name); | 2564 | kfree(intf->sysfs_name); |