Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

functionfs: switch to simple_remove_by_name()

No need to return dentry from ffs_sb_create_file() or keep it around
afterwards.

To avoid subtle issues with getting to ffs from epfiles in
ffs_epfiles_destroy(), pass the superblock as explicit argument.
Callers have it anyway.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro c7747faf e5bf5ee2

+22 -29
+22 -29
drivers/usb/gadget/function/f_fs.c
··· 160 160 struct ffs_data *ffs; 161 161 struct ffs_ep *ep; /* P: ffs->eps_lock */ 162 162 163 - struct dentry *dentry; 164 - 165 163 /* 166 164 * Buffer for holding data from partial reads which may happen since 167 165 * we’re rounding user read requests to a multiple of a max packet size. ··· 269 271 }; 270 272 271 273 static int __must_check ffs_epfiles_create(struct ffs_data *ffs); 272 - static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count); 274 + static void ffs_epfiles_destroy(struct super_block *sb, 275 + struct ffs_epfile *epfiles, unsigned count); 273 276 274 - static struct dentry * 275 - ffs_sb_create_file(struct super_block *sb, const char *name, void *data, 276 - const struct file_operations *fops); 277 + static int ffs_sb_create_file(struct super_block *sb, const char *name, 278 + void *data, const struct file_operations *fops); 277 279 278 280 /* Devices management *******************************************************/ 279 281 ··· 1892 1894 } 1893 1895 1894 1896 /* Create "regular" file */ 1895 - static struct dentry *ffs_sb_create_file(struct super_block *sb, 1896 - const char *name, void *data, 1897 - const struct file_operations *fops) 1897 + static int ffs_sb_create_file(struct super_block *sb, const char *name, 1898 + void *data, const struct file_operations *fops) 1898 1899 { 1899 1900 struct ffs_data *ffs = sb->s_fs_info; 1900 1901 struct dentry *dentry; ··· 1901 1904 1902 1905 dentry = d_alloc_name(sb->s_root, name); 1903 1906 if (!dentry) 1904 - return NULL; 1907 + return -ENOMEM; 1905 1908 1906 1909 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms); 1907 1910 if (!inode) { 1908 1911 dput(dentry); 1909 - return NULL; 1912 + return -ENOMEM; 1910 1913 } 1911 1914 1912 1915 d_add(dentry, inode); 1913 - return dentry; 1916 + return 0; 1914 1917 } 1915 1918 1916 1919 /* Super block */ ··· 1953 1956 return -ENOMEM; 1954 1957 1955 1958 /* EP0 file */ 1956 - if (!ffs_sb_create_file(sb, "ep0", ffs, &ffs_ep0_operations)) 1957 - return -ENOMEM; 1958 - 1959 - return 0; 1959 + return ffs_sb_create_file(sb, "ep0", ffs, &ffs_ep0_operations); 1960 1960 } 1961 1961 1962 1962 enum { ··· 2190 2196 flags); 2191 2197 2192 2198 if (epfiles) 2193 - ffs_epfiles_destroy(epfiles, 2199 + ffs_epfiles_destroy(ffs->sb, epfiles, 2194 2200 ffs->eps_count); 2195 2201 2196 2202 if (ffs->setup_state == FFS_SETUP_PENDING) ··· 2249 2255 * copy of epfile will save us from use-after-free. 2250 2256 */ 2251 2257 if (epfiles) { 2252 - ffs_epfiles_destroy(epfiles, ffs->eps_count); 2258 + ffs_epfiles_destroy(ffs->sb, epfiles, ffs->eps_count); 2253 2259 ffs->epfiles = NULL; 2254 2260 } 2255 2261 ··· 2346 2352 { 2347 2353 struct ffs_epfile *epfile, *epfiles; 2348 2354 unsigned i, count; 2355 + int err; 2349 2356 2350 2357 count = ffs->eps_count; 2351 2358 epfiles = kcalloc(count, sizeof(*epfiles), GFP_KERNEL); ··· 2363 2368 sprintf(epfile->name, "ep%02x", ffs->eps_addrmap[i]); 2364 2369 else 2365 2370 sprintf(epfile->name, "ep%u", i); 2366 - epfile->dentry = ffs_sb_create_file(ffs->sb, epfile->name, 2367 - epfile, 2368 - &ffs_epfile_operations); 2369 - if (!epfile->dentry) { 2370 - ffs_epfiles_destroy(epfiles, i - 1); 2371 - return -ENOMEM; 2371 + err = ffs_sb_create_file(ffs->sb, epfile->name, 2372 + epfile, &ffs_epfile_operations); 2373 + if (err) { 2374 + ffs_epfiles_destroy(ffs->sb, epfiles, i - 1); 2375 + return err; 2372 2376 } 2373 2377 } 2374 2378 ··· 2380 2386 smp_store_release(&dentry->d_inode->i_private, NULL); 2381 2387 } 2382 2388 2383 - static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count) 2389 + static void ffs_epfiles_destroy(struct super_block *sb, 2390 + struct ffs_epfile *epfiles, unsigned count) 2384 2391 { 2385 2392 struct ffs_epfile *epfile = epfiles; 2393 + struct dentry *root = sb->s_root; 2386 2394 2387 2395 for (; count; --count, ++epfile) { 2388 2396 BUG_ON(mutex_is_locked(&epfile->mutex)); 2389 - if (epfile->dentry) { 2390 - simple_recursive_removal(epfile->dentry, clear_one); 2391 - epfile->dentry = NULL; 2392 - } 2397 + simple_remove_by_name(root, epfile->name, clear_one); 2393 2398 } 2394 2399 2395 2400 kfree(epfiles);