diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-02-04 09:36:14 -0500 |
---|---|---|
committer | Corey Minyard <cminyard@mvista.com> | 2015-02-19 21:58:40 -0500 |
commit | 2d06a0c9b3756404e141cafcd62b29ce05238007 (patch) | |
tree | cd9e8476ce380098f8799b4c958f630f4f1c4186 /drivers/char/ipmi | |
parent | bdf2829cb673afc3aeb4f04531546c7605e8d94e (diff) |
ipmi: Use is_visible callback for conditional sysfs entries
Instead of manual calls of device_create_file() and
device_remove_file(), implement the condition in is_visible callback
for the attribute group and put these entries to the group, too.
This simplifies the code and avoids the possible races.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Corey Minyard <cminyard@mvista.com>
Diffstat (limited to 'drivers/char/ipmi')
-rw-r--r-- | drivers/char/ipmi/ipmi_msghandler.c | 60 |
1 files changed, 17 insertions, 43 deletions
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index 4891c39b3259..d5a2bd7230b2 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c | |||
@@ -2366,11 +2366,28 @@ static struct attribute *bmc_dev_attrs[] = { | |||
2366 | &dev_attr_additional_device_support.attr, | 2366 | &dev_attr_additional_device_support.attr, |
2367 | &dev_attr_manufacturer_id.attr, | 2367 | &dev_attr_manufacturer_id.attr, |
2368 | &dev_attr_product_id.attr, | 2368 | &dev_attr_product_id.attr, |
2369 | &dev_attr_aux_firmware_revision.attr, | ||
2370 | &dev_attr_guid.attr, | ||
2369 | NULL | 2371 | NULL |
2370 | }; | 2372 | }; |
2371 | 2373 | ||
2374 | static umode_t bmc_dev_attr_is_visible(struct kobject *kobj, | ||
2375 | struct attribute *attr, int idx) | ||
2376 | { | ||
2377 | struct device *dev = kobj_to_dev(kobj); | ||
2378 | struct bmc_device *bmc = to_bmc_device(dev); | ||
2379 | umode_t mode = attr->mode; | ||
2380 | |||
2381 | if (attr == &dev_attr_aux_firmware_revision.attr) | ||
2382 | return bmc->id.aux_firmware_revision_set ? mode : 0; | ||
2383 | if (attr == &dev_attr_guid.attr) | ||
2384 | return bmc->guid_set ? mode : 0; | ||
2385 | return mode; | ||
2386 | } | ||
2387 | |||
2372 | static struct attribute_group bmc_dev_attr_group = { | 2388 | static struct attribute_group bmc_dev_attr_group = { |
2373 | .attrs = bmc_dev_attrs, | 2389 | .attrs = bmc_dev_attrs, |
2390 | .is_visible = bmc_dev_attr_is_visible, | ||
2374 | }; | 2391 | }; |
2375 | 2392 | ||
2376 | static const struct attribute_group *bmc_dev_attr_groups[] = { | 2393 | static const struct attribute_group *bmc_dev_attr_groups[] = { |
@@ -2393,13 +2410,6 @@ cleanup_bmc_device(struct kref *ref) | |||
2393 | { | 2410 | { |
2394 | struct bmc_device *bmc = container_of(ref, struct bmc_device, usecount); | 2411 | struct bmc_device *bmc = container_of(ref, struct bmc_device, usecount); |
2395 | 2412 | ||
2396 | if (bmc->id.aux_firmware_revision_set) | ||
2397 | device_remove_file(&bmc->pdev.dev, | ||
2398 | &dev_attr_aux_firmware_revision); | ||
2399 | if (bmc->guid_set) | ||
2400 | device_remove_file(&bmc->pdev.dev, | ||
2401 | &dev_attr_guid); | ||
2402 | |||
2403 | platform_device_unregister(&bmc->pdev); | 2413 | platform_device_unregister(&bmc->pdev); |
2404 | } | 2414 | } |
2405 | 2415 | ||
@@ -2420,33 +2430,6 @@ static void ipmi_bmc_unregister(ipmi_smi_t intf) | |||
2420 | mutex_unlock(&ipmidriver_mutex); | 2430 | mutex_unlock(&ipmidriver_mutex); |
2421 | } | 2431 | } |
2422 | 2432 | ||
2423 | static int create_bmc_files(struct bmc_device *bmc) | ||
2424 | { | ||
2425 | int err; | ||
2426 | |||
2427 | if (bmc->id.aux_firmware_revision_set) { | ||
2428 | err = device_create_file(&bmc->pdev.dev, | ||
2429 | &dev_attr_aux_firmware_revision); | ||
2430 | if (err) | ||
2431 | goto out; | ||
2432 | } | ||
2433 | if (bmc->guid_set) { | ||
2434 | err = device_create_file(&bmc->pdev.dev, | ||
2435 | &dev_attr_guid); | ||
2436 | if (err) | ||
2437 | goto out_aux_firm; | ||
2438 | } | ||
2439 | |||
2440 | return 0; | ||
2441 | |||
2442 | out_aux_firm: | ||
2443 | if (bmc->id.aux_firmware_revision_set) | ||
2444 | device_remove_file(&bmc->pdev.dev, | ||
2445 | &dev_attr_aux_firmware_revision); | ||
2446 | out: | ||
2447 | return err; | ||
2448 | } | ||
2449 | |||
2450 | static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum) | 2433 | static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum) |
2451 | { | 2434 | { |
2452 | int rv; | 2435 | int rv; |
@@ -2535,15 +2518,6 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum) | |||
2535 | return rv; | 2518 | return rv; |
2536 | } | 2519 | } |
2537 | 2520 | ||
2538 | rv = create_bmc_files(bmc); | ||
2539 | if (rv) { | ||
2540 | mutex_lock(&ipmidriver_mutex); | ||
2541 | platform_device_unregister(&bmc->pdev); | ||
2542 | mutex_unlock(&ipmidriver_mutex); | ||
2543 | |||
2544 | return rv; | ||
2545 | } | ||
2546 | |||
2547 | dev_info(intf->si_dev, "Found new BMC (man_id: 0x%6.6x, " | 2521 | dev_info(intf->si_dev, "Found new BMC (man_id: 0x%6.6x, " |
2548 | "prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", | 2522 | "prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", |
2549 | bmc->id.manufacturer_id, | 2523 | bmc->id.manufacturer_id, |