Skip to content

Commit 01807c4

Browse files
committed
val: nvpair allocation helper should take a struct str *
Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
1 parent 27379e4 commit 01807c4

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

nvl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int nvl_set(struct nvlist *nvl, const char *name, struct val *val)
126126
pair = find(nvl, name);
127127
if (!pair) {
128128
/* not found - allocate a new pair */
129-
pair = __nvpair_alloc(name);
129+
pair = __nvpair_alloc(str_dup(name));
130130
if (!pair) {
131131
val_putref(val);
132132
return -ENOMEM;

val_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
extern struct val *__val_alloc(enum val_type type);
3030
extern void __val_free_nvl(struct val *val);
3131

32-
extern struct nvpair *__nvpair_alloc(const char *name);
32+
extern struct nvpair *__nvpair_alloc(struct str *name);
3333
extern void __nvpair_free(struct nvpair *pair);
3434

3535
static inline bool val_is_null_cons(struct val *v)

val_nvl.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,13 @@ static void __attribute__((constructor)) init_val_subsys(void)
3333
ASSERT(!IS_ERR(nvpair_cache));
3434
}
3535

36-
struct nvpair *__nvpair_alloc(const char *name)
36+
struct nvpair *__nvpair_alloc(struct str *name)
3737
{
3838
struct nvpair *pair;
3939

4040
pair = mem_cache_alloc(nvpair_cache);
41-
if (!pair)
42-
return NULL;
43-
44-
pair->name = str_dup(name);
45-
if (IS_ERR(pair->name)) {
46-
mem_cache_free(nvpair_cache, pair);
41+
if (!pair) {
42+
str_putref(name);
4743
return NULL;
4844
}
4945

@@ -55,6 +51,7 @@ struct nvpair *__nvpair_alloc(const char *name)
5551
* ->value is valid later on, even though we could have used
5652
* val_alloc_null directly as it never fails.)
5753
*/
54+
pair->name = name;
5855
pair->value = VAL_ALLOC_NULL();
5956

6057
return pair;

0 commit comments

Comments
 (0)