From d946f3fc08705ad3c8051fdf2869e9f8696e9747 Mon Sep 17 00:00:00 2001 From: Bruce Ashfield <bruce.ashfield@gmail.com> Date: Wed, 20 Oct 2021 21:43:58 -0400 Subject: [PATCH] yaffs: replace IS_ERR with IS_ERR_OR_NULL to check both ERR and NULL 1/1 [ Author: Meng Li Email: Meng.Li@windriver.com Subject: yaffs: replace IS_ERR with IS_ERR_OR_NULL to check both ERR and NULL Date: Thu, 21 Oct 2021 09:27:20 +0800 When run below command to mount a yaffs2 FS to nor flash, there is kernel panic as below: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020 ...... Internal error: Oops: 96000004 [#1] PREEMPT SMP Modules linked in: CPU: 1 PID: 335 Comm: mount Not tainted 5.10.73-yocto-standard #1 ...... Call trace: yaffs_internal_read_super.constprop.0+0x24c/0x6fc yaffs2_internal_read_super_mtd+0x28/0x40 mount_bdev+0x1cc/0x200 ...... el0_sync_handler+0x1a4/0x1b0 el0_sync+0x180/0x1c0 Because in function yaffs_get_mtd_device(), it check the type of mtd device. If it is not NAND flash, NULL will be returned. This causes kernel panic if the ret value is not checked whether it is NULL or not. So, replace IS_ERR with IS_ERR_OR_NULL to check both ERR and NULL. Signed-off-by: Meng Li <Meng.Li@windriver.com> Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com> ] Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com> --- ..._ERR-with-IS_ERR_OR_NULL-to-check-bo.patch | 49 +++++++++++++++++++ features/yaffs2/yaffs2.scc | 1 + 2 files changed, 50 insertions(+) create mode 100644 features/yaffs2/yaffs-replace-IS_ERR-with-IS_ERR_OR_NULL-to-check-bo.patch diff --git a/features/yaffs2/yaffs-replace-IS_ERR-with-IS_ERR_OR_NULL-to-check-bo.patch b/features/yaffs2/yaffs-replace-IS_ERR-with-IS_ERR_OR_NULL-to-check-bo.patch new file mode 100644 index 000000000..e0022e555 --- /dev/null +++ b/features/yaffs2/yaffs-replace-IS_ERR-with-IS_ERR_OR_NULL-to-check-bo.patch @@ -0,0 +1,49 @@ +From a8f317c1a17e3cab01708912f09c5e8fbc3702dc Mon Sep 17 00:00:00 2001 +From: Meng Li <Meng.Li@windriver.com> +Date: Thu, 21 Oct 2021 09:27:20 +0800 +Subject: [PATCH] yaffs: replace IS_ERR with IS_ERR_OR_NULL to check both ERR + and NULL + +When run below command to mount a yaffs2 FS to nor flash, there +is kernel panic as below: +Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020 +...... +Internal error: Oops: 96000004 [#1] PREEMPT SMP +Modules linked in: +CPU: 1 PID: 335 Comm: mount Not tainted 5.10.73-yocto-standard #1 +...... +Call trace: + yaffs_internal_read_super.constprop.0+0x24c/0x6fc + yaffs2_internal_read_super_mtd+0x28/0x40 + mount_bdev+0x1cc/0x200 + ...... + el0_sync_handler+0x1a4/0x1b0 + el0_sync+0x180/0x1c0 +Because in function yaffs_get_mtd_device(), it check the type of +mtd device. If it is not NAND flash, NULL will be returned. This +causes kernel panic if the ret value is not checked whether it +is NULL or not. So, replace IS_ERR with IS_ERR_OR_NULL to check +both ERR and NULL. + +Signed-off-by: Meng Li <Meng.Li@windriver.com> +Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com> +--- + fs/yaffs2/yaffs_vfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/fs/yaffs2/yaffs_vfs.c b/fs/yaffs2/yaffs_vfs.c +index a9cf8edc2245..eeb1b480d70e 100644 +--- a/fs/yaffs2/yaffs_vfs.c ++++ b/fs/yaffs2/yaffs_vfs.c +@@ -2964,7 +2964,7 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version, + + + mtd = yaffs_get_mtd_device(sb->s_dev); +- if (IS_ERR(mtd)) { ++ if (IS_ERR_OR_NULL(mtd)) { + return NULL; + } + +-- +2.19.1 + diff --git a/features/yaffs2/yaffs2.scc b/features/yaffs2/yaffs2.scc index a558a3db5..be1247ffa 100644 --- a/features/yaffs2/yaffs2.scc +++ b/features/yaffs2/yaffs2.scc @@ -13,3 +13,4 @@ patch yaffs2-v5.6-build-fixups.patch patch yaffs-fix-misplaced-variable-declaration.patch patch yaffs-include-blkdev.h.patch patch yaffs-fix-Wstringop-overread-compile-warning-in-yaff.patch +patch yaffs-replace-IS_ERR-with-IS_ERR_OR_NULL-to-check-bo.patch -- GitLab