Skip to content

Commit 4a29a12

Browse files
author
Al Viro
committed
minix: make minix_new_inode() return error as ERR_PTR(-E...)
adjust the callers Signed-off-by: Al Viro <[email protected]>
1 parent b7bfaa7 commit 4a29a12

File tree

3 files changed

+36
-50
lines changed

3 files changed

+36
-50
lines changed

fs/minix/bitmap.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void minix_free_inode(struct inode * inode)
210210
mark_buffer_dirty(bh);
211211
}
212212

213-
struct inode *minix_new_inode(const struct inode *dir, umode_t mode, int *error)
213+
struct inode *minix_new_inode(const struct inode *dir, umode_t mode)
214214
{
215215
struct super_block *sb = dir->i_sb;
216216
struct minix_sb_info *sbi = minix_sb(sb);
@@ -220,13 +220,10 @@ struct inode *minix_new_inode(const struct inode *dir, umode_t mode, int *error)
220220
unsigned long j;
221221
int i;
222222

223-
if (!inode) {
224-
*error = -ENOMEM;
225-
return NULL;
226-
}
223+
if (!inode)
224+
return ERR_PTR(-ENOMEM);
227225
j = bits_per_zone;
228226
bh = NULL;
229-
*error = -ENOSPC;
230227
spin_lock(&bitmap_lock);
231228
for (i = 0; i < sbi->s_imap_blocks; i++) {
232229
bh = sbi->s_imap[i];
@@ -237,20 +234,20 @@ struct inode *minix_new_inode(const struct inode *dir, umode_t mode, int *error)
237234
if (!bh || j >= bits_per_zone) {
238235
spin_unlock(&bitmap_lock);
239236
iput(inode);
240-
return NULL;
237+
return ERR_PTR(-ENOSPC);
241238
}
242239
if (minix_test_and_set_bit(j, bh->b_data)) { /* shouldn't happen */
243240
spin_unlock(&bitmap_lock);
244241
printk("minix_new_inode: bit already set\n");
245242
iput(inode);
246-
return NULL;
243+
return ERR_PTR(-ENOSPC);
247244
}
248245
spin_unlock(&bitmap_lock);
249246
mark_buffer_dirty(bh);
250247
j += i * bits_per_zone;
251248
if (!j || j > sbi->s_ninodes) {
252249
iput(inode);
253-
return NULL;
250+
return ERR_PTR(-ENOSPC);
254251
}
255252
inode_init_owner(&init_user_ns, inode, dir, mode);
256253
inode->i_ino = j;
@@ -260,7 +257,6 @@ struct inode *minix_new_inode(const struct inode *dir, umode_t mode, int *error)
260257
insert_inode_hash(inode);
261258
mark_inode_dirty(inode);
262259

263-
*error = 0;
264260
return inode;
265261
}
266262

fs/minix/minix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct minix_sb_info {
4545
extern struct inode *minix_iget(struct super_block *, unsigned long);
4646
extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, struct buffer_head **);
4747
extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
48-
extern struct inode * minix_new_inode(const struct inode *, umode_t, int *);
48+
extern struct inode * minix_new_inode(const struct inode *, umode_t);
4949
extern void minix_free_inode(struct inode * inode);
5050
extern unsigned long minix_count_free_inodes(struct super_block *sb);
5151
extern int minix_new_block(struct inode * inode);

fs/minix/namei.c

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,31 @@ static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry, un
3636
static int minix_mknod(struct user_namespace *mnt_userns, struct inode *dir,
3737
struct dentry *dentry, umode_t mode, dev_t rdev)
3838
{
39-
int error;
4039
struct inode *inode;
4140

4241
if (!old_valid_dev(rdev))
4342
return -EINVAL;
4443

45-
inode = minix_new_inode(dir, mode, &error);
44+
inode = minix_new_inode(dir, mode);
45+
if (IS_ERR(inode))
46+
return PTR_ERR(inode);
4647

47-
if (inode) {
48-
minix_set_inode(inode, rdev);
49-
mark_inode_dirty(inode);
50-
error = add_nondir(dentry, inode);
51-
}
52-
return error;
48+
minix_set_inode(inode, rdev);
49+
mark_inode_dirty(inode);
50+
return add_nondir(dentry, inode);
5351
}
5452

5553
static int minix_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
5654
struct file *file, umode_t mode)
5755
{
58-
int error;
59-
struct inode *inode = minix_new_inode(dir, mode, &error);
60-
if (inode) {
61-
minix_set_inode(inode, 0);
62-
mark_inode_dirty(inode);
63-
d_tmpfile(file, inode);
64-
}
65-
return finish_open_simple(file, error);
56+
struct inode *inode = minix_new_inode(dir, mode);
57+
58+
if (IS_ERR(inode))
59+
return finish_open_simple(file, PTR_ERR(inode));
60+
minix_set_inode(inode, 0);
61+
mark_inode_dirty(inode);
62+
d_tmpfile(file, inode);
63+
return finish_open_simple(file, 0);
6664
}
6765

6866
static int minix_create(struct user_namespace *mnt_userns, struct inode *dir,
@@ -74,30 +72,25 @@ static int minix_create(struct user_namespace *mnt_userns, struct inode *dir,
7472
static int minix_symlink(struct user_namespace *mnt_userns, struct inode *dir,
7573
struct dentry *dentry, const char *symname)
7674
{
77-
int err = -ENAMETOOLONG;
7875
int i = strlen(symname)+1;
7976
struct inode * inode;
77+
int err;
8078

8179
if (i > dir->i_sb->s_blocksize)
82-
goto out;
80+
return -ENAMETOOLONG;
8381

84-
inode = minix_new_inode(dir, S_IFLNK | 0777, &err);
85-
if (!inode)
86-
goto out;
82+
inode = minix_new_inode(dir, S_IFLNK | 0777);
83+
if (IS_ERR(inode))
84+
return PTR_ERR(inode);
8785

8886
minix_set_inode(inode, 0);
8987
err = page_symlink(inode, symname, i);
90-
if (err)
91-
goto out_fail;
92-
93-
err = add_nondir(dentry, inode);
94-
out:
95-
return err;
96-
97-
out_fail:
98-
inode_dec_link_count(inode);
99-
iput(inode);
100-
goto out;
88+
if (unlikely(err)) {
89+
inode_dec_link_count(inode);
90+
iput(inode);
91+
return err;
92+
}
93+
return add_nondir(dentry, inode);
10194
}
10295

10396
static int minix_link(struct dentry * old_dentry, struct inode * dir,
@@ -117,14 +110,12 @@ static int minix_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
117110
struct inode * inode;
118111
int err;
119112

120-
inode_inc_link_count(dir);
121-
122-
inode = minix_new_inode(dir, S_IFDIR | mode, &err);
123-
if (!inode)
124-
goto out_dir;
113+
inode = minix_new_inode(dir, S_IFDIR | mode);
114+
if (IS_ERR(inode))
115+
return PTR_ERR(inode);
125116

117+
inode_inc_link_count(dir);
126118
minix_set_inode(inode, 0);
127-
128119
inode_inc_link_count(inode);
129120

130121
err = minix_make_empty(inode, dir);
@@ -143,7 +134,6 @@ static int minix_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
143134
inode_dec_link_count(inode);
144135
inode_dec_link_count(inode);
145136
iput(inode);
146-
out_dir:
147137
inode_dec_link_count(dir);
148138
goto out;
149139
}

0 commit comments

Comments
 (0)