mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-23 04:34:11 +08:00
kobject: clean up rpadlpar horrid sysfs abuse
rpadlpar pci hotplug driver was doing some pretty bad stuff with the sysfs files. This cleans up the logic to be sane and gets rid of the gratuitous kset that is not needed for a simple directory like this. Note, this patch is not even build tested, let alone run-time tested. Someone with access to this hardware and can test would be greatly appreciated. Cc: Kay Sievers <kay.sievers@vrfy.org> Cc: John Rose <johnrose@austin.ibm.com> Cc: Badari Pulavarty <pbadari@gmail.com> Cc: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
2fb9113b97
commit
f55842f232
@ -23,43 +23,43 @@
|
|||||||
|
|
||||||
#define MAX_DRC_NAME_LEN 64
|
#define MAX_DRC_NAME_LEN 64
|
||||||
|
|
||||||
/* Store return code of dlpar operation in attribute struct */
|
|
||||||
struct dlpar_io_attr {
|
static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
|
||||||
|
const char *buf, size_t nbytes)
|
||||||
|
{
|
||||||
|
char drc_name[MAX_DRC_NAME_LEN];
|
||||||
|
char *end;
|
||||||
int rc;
|
int rc;
|
||||||
struct attribute attr;
|
|
||||||
ssize_t (*store)(struct dlpar_io_attr *dlpar_attr, const char *buf,
|
|
||||||
size_t nbytes);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Common show callback for all attrs, display the return code
|
if (nbytes >= MAX_DRC_NAME_LEN)
|
||||||
* of the dlpar op */
|
return 0;
|
||||||
static ssize_t
|
|
||||||
dlpar_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
|
memcpy(drc_name, buf, nbytes);
|
||||||
{
|
|
||||||
struct dlpar_io_attr *dlpar_attr = container_of(attr,
|
end = strchr(drc_name, '\n');
|
||||||
struct dlpar_io_attr, attr);
|
if (!end)
|
||||||
return sprintf(buf, "%d\n", dlpar_attr->rc);
|
end = &drc_name[nbytes];
|
||||||
|
*end = '\0';
|
||||||
|
|
||||||
|
rc = dlpar_add_slot(drc_name);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t add_slot_show(struct kobject *kobj,
|
||||||
dlpar_attr_store(struct kobject * kobj, struct attribute * attr,
|
struct kobj_attribute *attr, char *buf)
|
||||||
const char *buf, size_t nbytes)
|
|
||||||
{
|
{
|
||||||
struct dlpar_io_attr *dlpar_attr = container_of(attr,
|
return sprintf(buf, "0\n");
|
||||||
struct dlpar_io_attr, attr);
|
|
||||||
return dlpar_attr->store ?
|
|
||||||
dlpar_attr->store(dlpar_attr, buf, nbytes) : -EIO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sysfs_ops dlpar_attr_sysfs_ops = {
|
static ssize_t remove_slot_store(struct kobject *kobj,
|
||||||
.show = dlpar_attr_show,
|
struct kobj_attribute *attr,
|
||||||
.store = dlpar_attr_store,
|
const char *buf, size_t nbytes)
|
||||||
};
|
|
||||||
|
|
||||||
static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr,
|
|
||||||
const char *buf, size_t nbytes)
|
|
||||||
{
|
{
|
||||||
char drc_name[MAX_DRC_NAME_LEN];
|
char drc_name[MAX_DRC_NAME_LEN];
|
||||||
|
int rc;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
if (nbytes >= MAX_DRC_NAME_LEN)
|
if (nbytes >= MAX_DRC_NAME_LEN)
|
||||||
@ -72,43 +72,24 @@ static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr,
|
|||||||
end = &drc_name[nbytes];
|
end = &drc_name[nbytes];
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
|
|
||||||
dlpar_attr->rc = dlpar_add_slot(drc_name);
|
rc = dlpar_remove_slot(drc_name);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t remove_slot_store(struct dlpar_io_attr *dlpar_attr,
|
static ssize_t remove_slot_show(struct kobject *kobj,
|
||||||
const char *buf, size_t nbytes)
|
struct kobj_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
char drc_name[MAX_DRC_NAME_LEN];
|
return sprintf(buf, "0\n");
|
||||||
char *end;
|
|
||||||
|
|
||||||
if (nbytes >= MAX_DRC_NAME_LEN)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
memcpy(drc_name, buf, nbytes);
|
|
||||||
|
|
||||||
end = strchr(drc_name, '\n');
|
|
||||||
if (!end)
|
|
||||||
end = &drc_name[nbytes];
|
|
||||||
*end = '\0';
|
|
||||||
|
|
||||||
dlpar_attr->rc = dlpar_remove_slot(drc_name);
|
|
||||||
|
|
||||||
return nbytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dlpar_io_attr add_slot_attr = {
|
static struct kobj_attribute add_slot_attr =
|
||||||
.rc = 0,
|
__ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
|
||||||
.attr = { .name = ADD_SLOT_ATTR_NAME, .mode = 0644, },
|
|
||||||
.store = add_slot_store,
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct dlpar_io_attr remove_slot_attr = {
|
static struct kobj_attribute remove_slot_attr =
|
||||||
.rc = 0,
|
__ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
|
||||||
.attr = { .name = REMOVE_SLOT_ATTR_NAME, .mode = 0644},
|
|
||||||
.store = remove_slot_store,
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct attribute *default_attrs[] = {
|
static struct attribute *default_attrs[] = {
|
||||||
&add_slot_attr.attr,
|
&add_slot_attr.attr,
|
||||||
@ -116,36 +97,29 @@ static struct attribute *default_attrs[] = {
|
|||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void dlpar_io_release(struct kobject *kobj)
|
static struct attribute_group dlpar_attr_group = {
|
||||||
{
|
.attrs = default_attrs,
|
||||||
/* noop */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct kobj_type ktype_dlpar_io = {
|
|
||||||
.release = dlpar_io_release,
|
|
||||||
.sysfs_ops = &dlpar_attr_sysfs_ops,
|
|
||||||
.default_attrs = default_attrs,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct kset dlpar_io_kset = {
|
static struct kobject *dlpar_kobj;
|
||||||
.kobj = {.ktype = &ktype_dlpar_io,
|
|
||||||
.parent = &pci_hotplug_slots_kset->kobj},
|
|
||||||
};
|
|
||||||
|
|
||||||
int dlpar_sysfs_init(void)
|
int dlpar_sysfs_init(void)
|
||||||
{
|
{
|
||||||
kobject_set_name(&dlpar_io_kset.kobj, DLPAR_KOBJ_NAME);
|
int error;
|
||||||
if (kset_register(&dlpar_io_kset)) {
|
|
||||||
printk(KERN_ERR "rpadlpar_io: cannot register kset for %s\n",
|
|
||||||
kobject_name(&dlpar_io_kset.kobj));
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
|
||||||
|
&pci_hotplug_slots_kset->kobj);
|
||||||
|
if (!dlpar_kobj)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
|
||||||
|
if (error)
|
||||||
|
kobject_unregister(dlpar_kobj);
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dlpar_sysfs_exit(void)
|
void dlpar_sysfs_exit(void)
|
||||||
{
|
{
|
||||||
kset_unregister(&dlpar_io_kset);
|
sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
|
||||||
|
kobject_unregister(dlpar_kobj);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user