2019-06-01 15:08:42 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-12-20 17:02:21 +07:00
|
|
|
/*
|
|
|
|
* Architecture specific sysfs attributes in /sys/kernel
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007, Intel Corp.
|
|
|
|
* Huang Ying <ying.huang@intel.com>
|
|
|
|
* Copyright (C) 2013, 2013 Red Hat, Inc.
|
|
|
|
* Dave Young <dyoung@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kobject.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mm.h>
|
2017-07-18 04:10:00 +07:00
|
|
|
#include <linux/io.h>
|
2013-12-20 17:02:21 +07:00
|
|
|
|
|
|
|
#include <asm/setup.h>
|
|
|
|
|
|
|
|
static ssize_t version_show(struct kobject *kobj,
|
|
|
|
struct kobj_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "0x%04x\n", boot_params.hdr.version);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct kobj_attribute boot_params_version_attr = __ATTR_RO(version);
|
|
|
|
|
|
|
|
static ssize_t boot_params_data_read(struct file *fp, struct kobject *kobj,
|
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buf, loff_t off, size_t count)
|
|
|
|
{
|
|
|
|
memcpy(buf, (void *)&boot_params + off, count);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bin_attribute boot_params_data_attr = {
|
|
|
|
.attr = {
|
|
|
|
.name = "data",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
|
|
|
.read = boot_params_data_read,
|
|
|
|
.size = sizeof(boot_params),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute *boot_params_version_attrs[] = {
|
|
|
|
&boot_params_version_attr.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct bin_attribute *boot_params_data_attrs[] = {
|
|
|
|
&boot_params_data_attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2017-07-20 18:30:32 +07:00
|
|
|
static const struct attribute_group boot_params_attr_group = {
|
2013-12-20 17:02:21 +07:00
|
|
|
.attrs = boot_params_version_attrs,
|
|
|
|
.bin_attrs = boot_params_data_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int kobj_to_setup_data_nr(struct kobject *kobj, int *nr)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = kobject_name(kobj);
|
|
|
|
return kstrtoint(name, 10, nr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_setup_data_paddr(int nr, u64 *paddr)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
struct setup_data *data;
|
|
|
|
u64 pa_data = boot_params.hdr.setup_data;
|
|
|
|
|
|
|
|
while (pa_data) {
|
|
|
|
if (nr == i) {
|
|
|
|
*paddr = pa_data;
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-18 04:10:00 +07:00
|
|
|
data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
|
2013-12-20 17:02:21 +07:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pa_data = data->next;
|
2017-07-18 04:10:00 +07:00
|
|
|
memunmap(data);
|
2013-12-20 17:02:21 +07:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init get_setup_data_size(int nr, size_t *size)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
struct setup_data *data;
|
|
|
|
u64 pa_data = boot_params.hdr.setup_data;
|
|
|
|
|
|
|
|
while (pa_data) {
|
2017-07-18 04:10:00 +07:00
|
|
|
data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
|
2013-12-20 17:02:21 +07:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (nr == i) {
|
2019-11-12 20:46:40 +07:00
|
|
|
if (data->type == SETUP_INDIRECT &&
|
|
|
|
((struct setup_indirect *)data->data)->type != SETUP_INDIRECT)
|
|
|
|
*size = ((struct setup_indirect *)data->data)->len;
|
|
|
|
else
|
|
|
|
*size = data->len;
|
|
|
|
|
2017-07-18 04:10:00 +07:00
|
|
|
memunmap(data);
|
2013-12-20 17:02:21 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pa_data = data->next;
|
2017-07-18 04:10:00 +07:00
|
|
|
memunmap(data);
|
2013-12-20 17:02:21 +07:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t type_show(struct kobject *kobj,
|
|
|
|
struct kobj_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
int nr, ret;
|
|
|
|
u64 paddr;
|
|
|
|
struct setup_data *data;
|
|
|
|
|
|
|
|
ret = kobj_to_setup_data_nr(kobj, &nr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = get_setup_data_paddr(nr, &paddr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-07-18 04:10:00 +07:00
|
|
|
data = memremap(paddr, sizeof(*data), MEMREMAP_WB);
|
2013-12-20 17:02:21 +07:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-11-12 20:46:40 +07:00
|
|
|
if (data->type == SETUP_INDIRECT)
|
|
|
|
ret = sprintf(buf, "0x%x\n", ((struct setup_indirect *)data->data)->type);
|
|
|
|
else
|
|
|
|
ret = sprintf(buf, "0x%x\n", data->type);
|
2017-07-18 04:10:00 +07:00
|
|
|
memunmap(data);
|
2013-12-20 17:02:21 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t setup_data_data_read(struct file *fp,
|
|
|
|
struct kobject *kobj,
|
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buf,
|
|
|
|
loff_t off, size_t count)
|
|
|
|
{
|
|
|
|
int nr, ret = 0;
|
2019-11-12 20:46:40 +07:00
|
|
|
u64 paddr, len;
|
2013-12-20 17:02:21 +07:00
|
|
|
struct setup_data *data;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
ret = kobj_to_setup_data_nr(kobj, &nr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = get_setup_data_paddr(nr, &paddr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-07-18 04:10:00 +07:00
|
|
|
data = memremap(paddr, sizeof(*data), MEMREMAP_WB);
|
2013-12-20 17:02:21 +07:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-11-12 20:46:40 +07:00
|
|
|
if (data->type == SETUP_INDIRECT &&
|
|
|
|
((struct setup_indirect *)data->data)->type != SETUP_INDIRECT) {
|
|
|
|
paddr = ((struct setup_indirect *)data->data)->addr;
|
|
|
|
len = ((struct setup_indirect *)data->data)->len;
|
|
|
|
} else {
|
|
|
|
paddr += sizeof(*data);
|
|
|
|
len = data->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (off > len) {
|
2013-12-20 17:02:21 +07:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-11-12 20:46:40 +07:00
|
|
|
if (count > len - off)
|
|
|
|
count = len - off;
|
2013-12-20 17:02:21 +07:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = count;
|
2019-11-12 20:46:40 +07:00
|
|
|
p = memremap(paddr, len, MEMREMAP_WB);
|
2013-12-20 17:02:21 +07:00
|
|
|
if (!p) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
memcpy(buf, p + off, count);
|
2017-07-18 04:10:00 +07:00
|
|
|
memunmap(p);
|
2013-12-20 17:02:21 +07:00
|
|
|
out:
|
2017-07-18 04:10:00 +07:00
|
|
|
memunmap(data);
|
2013-12-20 17:02:21 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct kobj_attribute type_attr = __ATTR_RO(type);
|
|
|
|
|
2016-08-09 06:29:06 +07:00
|
|
|
static struct bin_attribute data_attr __ro_after_init = {
|
2013-12-20 17:02:21 +07:00
|
|
|
.attr = {
|
|
|
|
.name = "data",
|
|
|
|
.mode = S_IRUGO,
|
|
|
|
},
|
|
|
|
.read = setup_data_data_read,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute *setup_data_type_attrs[] = {
|
|
|
|
&type_attr.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct bin_attribute *setup_data_data_attrs[] = {
|
|
|
|
&data_attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2017-07-20 18:30:32 +07:00
|
|
|
static const struct attribute_group setup_data_attr_group = {
|
2013-12-20 17:02:21 +07:00
|
|
|
.attrs = setup_data_type_attrs,
|
|
|
|
.bin_attrs = setup_data_data_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init create_setup_data_node(struct kobject *parent,
|
|
|
|
struct kobject **kobjp, int nr)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
size_t size;
|
|
|
|
struct kobject *kobj;
|
|
|
|
char name[16]; /* should be enough for setup_data nodes numbers */
|
|
|
|
snprintf(name, 16, "%d", nr);
|
|
|
|
|
|
|
|
kobj = kobject_create_and_add(name, parent);
|
|
|
|
if (!kobj)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = get_setup_data_size(nr, &size);
|
|
|
|
if (ret)
|
|
|
|
goto out_kobj;
|
|
|
|
|
|
|
|
data_attr.size = size;
|
|
|
|
ret = sysfs_create_group(kobj, &setup_data_attr_group);
|
|
|
|
if (ret)
|
|
|
|
goto out_kobj;
|
|
|
|
*kobjp = kobj;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_kobj:
|
|
|
|
kobject_put(kobj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init cleanup_setup_data_node(struct kobject *kobj)
|
|
|
|
{
|
|
|
|
sysfs_remove_group(kobj, &setup_data_attr_group);
|
|
|
|
kobject_put(kobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init get_setup_data_total_num(u64 pa_data, int *nr)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct setup_data *data;
|
|
|
|
|
|
|
|
*nr = 0;
|
|
|
|
while (pa_data) {
|
|
|
|
*nr += 1;
|
2017-07-18 04:10:00 +07:00
|
|
|
data = memremap(pa_data, sizeof(*data), MEMREMAP_WB);
|
2013-12-20 17:02:21 +07:00
|
|
|
if (!data) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
pa_data = data->next;
|
2017-07-18 04:10:00 +07:00
|
|
|
memunmap(data);
|
2013-12-20 17:02:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init create_setup_data_nodes(struct kobject *parent)
|
|
|
|
{
|
|
|
|
struct kobject *setup_data_kobj, **kobjp;
|
|
|
|
u64 pa_data;
|
|
|
|
int i, j, nr, ret = 0;
|
|
|
|
|
|
|
|
pa_data = boot_params.hdr.setup_data;
|
|
|
|
if (!pa_data)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
setup_data_kobj = kobject_create_and_add("setup_data", parent);
|
|
|
|
if (!setup_data_kobj) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = get_setup_data_total_num(pa_data, &nr);
|
|
|
|
if (ret)
|
|
|
|
goto out_setup_data_kobj;
|
|
|
|
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 03:55:00 +07:00
|
|
|
kobjp = kmalloc_array(nr, sizeof(*kobjp), GFP_KERNEL);
|
2013-12-20 17:02:21 +07:00
|
|
|
if (!kobjp) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_setup_data_kobj;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nr; i++) {
|
|
|
|
ret = create_setup_data_node(setup_data_kobj, kobjp + i, i);
|
|
|
|
if (ret)
|
|
|
|
goto out_clean_nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(kobjp);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_clean_nodes:
|
2017-09-11 07:33:21 +07:00
|
|
|
for (j = i - 1; j >= 0; j--)
|
2013-12-20 17:02:21 +07:00
|
|
|
cleanup_setup_data_node(*(kobjp + j));
|
|
|
|
kfree(kobjp);
|
|
|
|
out_setup_data_kobj:
|
|
|
|
kobject_put(setup_data_kobj);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init boot_params_ksysfs_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct kobject *boot_params_kobj;
|
|
|
|
|
|
|
|
boot_params_kobj = kobject_create_and_add("boot_params",
|
|
|
|
kernel_kobj);
|
|
|
|
if (!boot_params_kobj) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sysfs_create_group(boot_params_kobj, &boot_params_attr_group);
|
|
|
|
if (ret)
|
|
|
|
goto out_boot_params_kobj;
|
|
|
|
|
|
|
|
ret = create_setup_data_nodes(boot_params_kobj);
|
|
|
|
if (ret)
|
|
|
|
goto out_create_group;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_create_group:
|
|
|
|
sysfs_remove_group(boot_params_kobj, &boot_params_attr_group);
|
|
|
|
out_boot_params_kobj:
|
|
|
|
kobject_put(boot_params_kobj);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
arch_initcall(boot_params_ksysfs_init);
|