Skip to contentSkip to conversation

afs: kstrdup() memory handling

PATCH In review Sanidhya Kashyap 2 participants 5 messages Mar 21, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 afs: kstrdup() memory handling

Handling kstrdup() failure in case of memory pressure even for new_opts.

---
 fs/afs/super.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/afs/super.c +5 -1
index c486155..477f38e 100644
@@ -360,10 +360,13 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
 	struct key *key;
 	char *new_opts = kstrdup(options, GFP_KERNEL);
 	struct afs_super_info *as;
-	int ret;
+	int ret = -ENOMEM;
 
 	_enter(",,%s,%p", dev_name, options);
 
+	if (new_opts)
+		goto error_out;
+
 	memset(&params, 0, sizeof(params));
 
 	ret = -EINVAL;
@@ -441,6 +444,7 @@ error:
 	afs_put_cell(params.cell);
 	key_put(params.key);
 	kfree(new_opts);
+error_out:
 	_leave(" = %d", ret);
 	return ERR_PTR(ret);
 }
Signature · 1 line
2.1.0
#1 lore raw

fs/afs/super.c static struct dentry *afs_mount(struct file_system_type *fs_type, · line 368

Quoted 2 lines · Sanidhya Kashyap
fs/afs/super.c +2 -0
+	if (new_opts)
+		goto error_out;

Missing "!"?

Jeff

#2 lore raw
Quoted 6 lines · Jeff Epler

fs/afs/super.c static struct dentry *afs_mount(struct file_system_type *fs_type, · line 368

Quoted 2 lines · Sanidhya Kashyap
fs/afs/super.c +2 -0
+     if (new_opts)
+             goto error_out;

Missing "!"?

Ohh! Sorry, missed it!

Resending the patch?

Thanks,
Sanidhya

Quoted 1 line

Jeff

#3 lore raw

PATCH 1/1 afs: kstrdup() memory handling

In reply to Sanidhya Kashyap

Handling kstrdup() failure in case of memory pressure even for new_opts.

---
 fs/afs/super.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/afs/super.c +5 -1
index c486155..477f38e 100644
@@ -360,10 +360,13 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
 	struct key *key;
 	char *new_opts = kstrdup(options, GFP_KERNEL);
 	struct afs_super_info *as;
-	int ret;
+	int ret = -ENOMEM;
 
 	_enter(",,%s,%p", dev_name, options);
 
+	if (!new_opts)
+		goto error_out;
+
 	memset(&params, 0, sizeof(params));
 
 	ret = -EINVAL;
@@ -441,6 +444,7 @@ error:
 	afs_put_cell(params.cell);
 	key_put(params.key);
 	kfree(new_opts);
+error_out:
 	_leave(" = %d", ret);
 	return ERR_PTR(ret);
 }
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#4 lore raw
Quoted 4 lines · Sanidhya Kashyap

Handling kstrdup() failure in case of memory pressure even for new_opts.

Quoted 40 lines
---
 fs/afs/super.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/afs/super.c +5 -1
index c486155..477f38e 100644
@@ -360,10 +360,13 @@ static struct dentry *afs_mount(struct file_system_type *fs_type,
 	struct key *key;
 	char *new_opts = kstrdup(options, GFP_KERNEL);
 	struct afs_super_info *as;
-	int ret;
+	int ret = -ENOMEM;
 
 	_enter(",,%s,%p", dev_name, options);
 
+	if (!new_opts)
+		goto error_out;
+
 	memset(&params, 0, sizeof(params));
 
 	ret = -EINVAL;
@@ -441,6 +444,7 @@ error:
 	afs_put_cell(params.cell);
 	key_put(params.key);
 	kfree(new_opts);
+error_out:
 	_leave(" = %d", ret);
 	return ERR_PTR(ret);
 }
Signature · 7 lines
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/