Skip to content

Commit 2d06a0c

Browse files
tiwaicminyard
authored andcommitted
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>
1 parent bdf2829 commit 2d06a0c

File tree

1 file changed

+17
-43
lines changed

1 file changed

+17
-43
lines changed

drivers/char/ipmi/ipmi_msghandler.c

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,11 +2366,28 @@ static struct attribute *bmc_dev_attrs[] = {
23662366
&dev_attr_additional_device_support.attr,
23672367
&dev_attr_manufacturer_id.attr,
23682368
&dev_attr_product_id.attr,
2369+
&dev_attr_aux_firmware_revision.attr,
2370+
&dev_attr_guid.attr,
23692371
NULL
23702372
};
23712373

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+
23722388
static struct attribute_group bmc_dev_attr_group = {
23732389
.attrs = bmc_dev_attrs,
2390+
.is_visible = bmc_dev_attr_is_visible,
23742391
};
23752392

23762393
static const struct attribute_group *bmc_dev_attr_groups[] = {
@@ -2393,13 +2410,6 @@ cleanup_bmc_device(struct kref *ref)
23932410
{
23942411
struct bmc_device *bmc = container_of(ref, struct bmc_device, usecount);
23952412

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-
24032413
platform_device_unregister(&bmc->pdev);
24042414
}
24052415

@@ -2420,33 +2430,6 @@ static void ipmi_bmc_unregister(ipmi_smi_t intf)
24202430
mutex_unlock(&ipmidriver_mutex);
24212431
}
24222432

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-
24502433
static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum)
24512434
{
24522435
int rv;
@@ -2535,15 +2518,6 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum)
25352518
return rv;
25362519
}
25372520

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-
25472521
dev_info(intf->si_dev, "Found new BMC (man_id: 0x%6.6x, "
25482522
"prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n",
25492523
bmc->id.manufacturer_id,

0 commit comments

Comments
 (0)