MIPS: Yosemite, Emma: Fix off-by-two in arcs_cmdline buffer size check
[linux-2.6/linux-mips.git] / drivers / pci / hotplug / rpadlpar_sysfs.c
bloba796301ea03fbd3709f15be52f78053bb12380f9
1 /*
2 * Interface for Dynamic Logical Partitioning of I/O Slots on
3 * RPA-compliant PPC64 platform.
5 * John Rose <johnrose@austin.ibm.com>
6 * October 2003
8 * Copyright (C) 2003 IBM.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
15 #include <linux/kobject.h>
16 #include <linux/string.h>
17 #include <linux/pci.h>
18 #include <linux/pci_hotplug.h>
19 #include "rpadlpar.h"
20 #include "../pci.h"
22 #define DLPAR_KOBJ_NAME "control"
24 /* Those two have no quotes because they are passed to __ATTR() which
25 * stringifies the argument (yuck !)
27 #define ADD_SLOT_ATTR_NAME add_slot
28 #define REMOVE_SLOT_ATTR_NAME remove_slot
30 #define MAX_DRC_NAME_LEN 64
32 static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
33 const char *buf, size_t nbytes)
35 char drc_name[MAX_DRC_NAME_LEN];
36 char *end;
37 int rc;
39 if (nbytes >= MAX_DRC_NAME_LEN)
40 return 0;
42 memcpy(drc_name, buf, nbytes);
44 end = strchr(drc_name, '\n');
45 if (!end)
46 end = &drc_name[nbytes];
47 *end = '\0';
49 rc = dlpar_add_slot(drc_name);
50 if (rc)
51 return rc;
53 return nbytes;
56 static ssize_t add_slot_show(struct kobject *kobj,
57 struct kobj_attribute *attr, char *buf)
59 return sprintf(buf, "0\n");
62 static ssize_t remove_slot_store(struct kobject *kobj,
63 struct kobj_attribute *attr,
64 const char *buf, size_t nbytes)
66 char drc_name[MAX_DRC_NAME_LEN];
67 int rc;
68 char *end;
70 if (nbytes >= MAX_DRC_NAME_LEN)
71 return 0;
73 memcpy(drc_name, buf, nbytes);
75 end = strchr(drc_name, '\n');
76 if (!end)
77 end = &drc_name[nbytes];
78 *end = '\0';
80 rc = dlpar_remove_slot(drc_name);
81 if (rc)
82 return rc;
84 return nbytes;
87 static ssize_t remove_slot_show(struct kobject *kobj,
88 struct kobj_attribute *attr, char *buf)
90 return sprintf(buf, "0\n");
93 static struct kobj_attribute add_slot_attr =
94 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
96 static struct kobj_attribute remove_slot_attr =
97 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
99 static struct attribute *default_attrs[] = {
100 &add_slot_attr.attr,
101 &remove_slot_attr.attr,
102 NULL,
105 static struct attribute_group dlpar_attr_group = {
106 .attrs = default_attrs,
109 static struct kobject *dlpar_kobj;
111 int dlpar_sysfs_init(void)
113 int error;
115 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
116 &pci_slots_kset->kobj);
117 if (!dlpar_kobj)
118 return -EINVAL;
120 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
121 if (error)
122 kobject_put(dlpar_kobj);
123 return error;
126 void dlpar_sysfs_exit(void)
128 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
129 kobject_put(dlpar_kobj);