]> git.baikalelectronics.ru Git - kernel.git/commitdiff
hfs/hfsplus: use WARN_ON for sanity check
authorArnd Bergmann <arnd@arndb.de>
Tue, 9 Nov 2021 02:35:04 +0000 (18:35 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:59 +0000 (11:41 +0100)
commit 558a16210318c017f86674a959a6ca9be6ed433e upstream.

gcc warns about a couple of instances in which a sanity check exists but
the author wasn't sure how to react to it failing, which makes it look
like a possible bug:

  fs/hfsplus/inode.c: In function 'hfsplus_cat_read_inode':
  fs/hfsplus/inode.c:503:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
    503 |                         /* panic? */;
        |                                     ^
  fs/hfsplus/inode.c:524:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
    524 |                         /* panic? */;
        |                                     ^
  fs/hfsplus/inode.c: In function 'hfsplus_cat_write_inode':
  fs/hfsplus/inode.c:582:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
    582 |                         /* panic? */;
        |                                     ^
  fs/hfsplus/inode.c:608:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
    608 |                         /* panic? */;
        |                                     ^
  fs/hfs/inode.c: In function 'hfs_write_inode':
  fs/hfs/inode.c:464:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
    464 |                         /* panic? */;
        |                                     ^
  fs/hfs/inode.c:485:37: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
    485 |                         /* panic? */;
        |                                     ^

panic() is probably not the correct choice here, but a WARN_ON
seems appropriate and avoids the compile-time warning.

Link: https://lkml.kernel.org/r/20210927102149.1809384-1-arnd@kernel.org
Link: https://lore.kernel.org/all/20210322223249.2632268-1-arnd@kernel.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/hfs/inode.c
fs/hfsplus/inode.c

index 9c5badc9db009fe8724b1fb31f5f8406f5df132f..a537cebf7a628a9c622ec8622d69e1ae5c260446 100644 (file)
@@ -461,8 +461,7 @@ int hfs_write_inode(struct inode *inode, struct writeback_control *wbc)
                goto out;
 
        if (S_ISDIR(main_inode->i_mode)) {
-               if (fd.entrylength < sizeof(struct hfs_cat_dir))
-                       /* panic? */;
+               WARN_ON(fd.entrylength < sizeof(struct hfs_cat_dir));
                hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
                           sizeof(struct hfs_cat_dir));
                if (rec.type != HFS_CDR_DIR ||
@@ -482,8 +481,7 @@ int hfs_write_inode(struct inode *inode, struct writeback_control *wbc)
                hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
                                sizeof(struct hfs_cat_file));
        } else {
-               if (fd.entrylength < sizeof(struct hfs_cat_file))
-                       /* panic? */;
+               WARN_ON(fd.entrylength < sizeof(struct hfs_cat_file));
                hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
                           sizeof(struct hfs_cat_file));
                if (rec.type != HFS_CDR_FIL ||
index ec7ade4b75a18680c042f0f617462eb97c3782e5..76501d905099b7c49c87fa33a912747a861557b5 100644 (file)
@@ -497,8 +497,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
        if (type == HFSPLUS_FOLDER) {
                struct hfsplus_cat_folder *folder = &entry.folder;
 
-               if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
-                       /* panic? */;
+               WARN_ON(fd->entrylength < sizeof(struct hfsplus_cat_folder));
                hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
                                        sizeof(struct hfsplus_cat_folder));
                hfsplus_get_perms(inode, &folder->permissions, 1);
@@ -518,8 +517,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
        } else if (type == HFSPLUS_FILE) {
                struct hfsplus_cat_file *file = &entry.file;
 
-               if (fd->entrylength < sizeof(struct hfsplus_cat_file))
-                       /* panic? */;
+               WARN_ON(fd->entrylength < sizeof(struct hfsplus_cat_file));
                hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
                                        sizeof(struct hfsplus_cat_file));
 
@@ -576,8 +574,7 @@ int hfsplus_cat_write_inode(struct inode *inode)
        if (S_ISDIR(main_inode->i_mode)) {
                struct hfsplus_cat_folder *folder = &entry.folder;
 
-               if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
-                       /* panic? */;
+               WARN_ON(fd.entrylength < sizeof(struct hfsplus_cat_folder));
                hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
                                        sizeof(struct hfsplus_cat_folder));
                /* simple node checks? */
@@ -602,8 +599,7 @@ int hfsplus_cat_write_inode(struct inode *inode)
        } else {
                struct hfsplus_cat_file *file = &entry.file;
 
-               if (fd.entrylength < sizeof(struct hfsplus_cat_file))
-                       /* panic? */;
+               WARN_ON(fd.entrylength < sizeof(struct hfsplus_cat_file));
                hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
                                        sizeof(struct hfsplus_cat_file));
                hfsplus_inode_write_fork(inode, &file->data_fork);