linux-stable/fs
Yang Yingliang 6acf8597c5 chardev: fix error handling in cdev_device_add()
[ Upstream commit 11fa7fefe3 ]

While doing fault injection test, I got the following report:

------------[ cut here ]------------
kobject: '(null)' (0000000039956980): is not initialized, yet kobject_put() is being called.
WARNING: CPU: 3 PID: 6306 at kobject_put+0x23d/0x4e0
CPU: 3 PID: 6306 Comm: 283 Tainted: G        W          6.1.0-rc2-00005-g307c1086d7c9 #1253
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
RIP: 0010:kobject_put+0x23d/0x4e0
Call Trace:
 <TASK>
 cdev_device_add+0x15e/0x1b0
 __iio_device_register+0x13b4/0x1af0 [industrialio]
 __devm_iio_device_register+0x22/0x90 [industrialio]
 max517_probe+0x3d8/0x6b4 [max517]
 i2c_device_probe+0xa81/0xc00

When device_add() is injected fault and returns error, if dev->devt is not set,
cdev_add() is not called, cdev_del() is not needed. Fix this by checking dev->devt
in error path.

Fixes: 233ed09d7f ("chardev: add helper function to register char devs with a struct device")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221202030237.520280-1-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-01-18 09:26:24 +01:00
..
9p 9p: missing chunk of "fs/9p: Don't update file type when updating file attributes" 2022-06-25 11:46:24 +02:00
adfs
affs
afs
autofs4
befs
bfs
btrfs btrfs: qgroup: fix sleep from invalid context bug in btrfs_qgroup_inherit() 2022-12-08 11:16:32 +01:00
cachefiles
ceph ceph: don't truncate file in atomic_open 2022-10-26 13:16:53 +02:00
cifs cifs: Fix wrong return value checking when GETFLAGS 2022-11-25 17:36:51 +01:00
coda
configfs configfs: fix a race in configfs_{,un}register_subsystem() 2022-03-02 11:33:56 +01:00
cramfs
crypto fscrypt: don't ignore minor_hash when hash is 0 2021-07-20 16:17:45 +02:00
debugfs
devpts
dlm fs: dlm: handle -EBUSY first in lock arg validation 2022-10-26 13:16:55 +02:00
ecryptfs Revert "ecryptfs: replace BUG_ON with error handling code" 2021-05-26 11:47:00 +02:00
efivarfs
efs
exofs
exportfs
ext2 ext2: Add more validity checks for inode counts 2022-08-25 11:11:14 +02:00
ext4 ext4: fix warning in 'ext4_da_release_space' 2022-11-10 15:47:23 +01:00
f2fs f2fs: fix race condition on setting FI_NO_EXTENT flag 2022-10-26 13:17:08 +02:00
fat fat: add ratelimit to fat*_ent_bread() 2022-06-14 16:53:46 +02:00
freevxfs
fscache
fuse fuse: limit nsec 2022-08-25 11:11:12 +02:00
gfs2 gfs2: Switch from strlcpy to strscpy 2022-11-25 17:36:55 +01:00
hfs hfs: Fix OOB Write in hfs_asc2mac 2023-01-18 09:26:11 +01:00
hfsplus
hostfs
hpfs
hugetlbfs hugetlbfs: hugetlb_fault_mutex_hash() cleanup 2021-06-03 08:36:25 +02:00
isofs isofs: Fix out of bound access for corrupted isofs image 2021-11-12 14:28:24 +01:00
jbd2 jbd2: fix assertion 'jh->b_frozen_data == NULL' failure when journal aborted 2022-08-25 11:11:23 +02:00
jffs2 jffs2: fix memory leak in jffs2_do_fill_super 2022-06-14 16:53:57 +02:00
jfs fs: jfs: fix possible NULL pointer dereference in dbFree() 2022-06-14 16:53:46 +02:00
kernfs kernfs: fix use-after-free in __kernfs_remove 2022-11-03 23:50:53 +09:00
lockd
minix
ncpfs
nfs NFSv4.x: Fail client initialisation if state manager thread can't run 2023-01-18 09:26:16 +01:00
nfs_common
nfsd NFSD: Return nfserr_serverfault if splice_ok but buf->pages have data 2022-10-26 13:17:09 +02:00
nilfs2 nilfs2: fix NULL pointer dereference in nilfs_palloc_commit_free_entry() 2022-12-08 11:16:32 +01:00
nls
notify fsnotify: fix wrong lockdep annotations 2022-06-14 16:53:48 +02:00
ntfs ntfs: check overflow when iterating ATTR_RECORDs 2022-11-25 17:36:55 +01:00
ocfs2 ocfs2: fix memory leak in ocfs2_stack_glue_init() 2023-01-18 09:26:09 +01:00
omfs
openpromfs
orangefs orangefs: Fix sysfs not cleanup when dev init failed 2023-01-18 09:26:22 +01:00
overlayfs ovl: fix missing negative dentry check in ovl_rename() 2021-10-17 10:08:32 +02:00
proc proc/vmcore: fix clearing user buffer by properly using clear_user() 2021-12-08 08:46:52 +01:00
pstore pstore: Avoid kcore oops by vmap()ing with VM_IOREMAP 2023-01-18 09:26:09 +01:00
qnx4 qnx4: work around gcc false positive warning bug 2021-10-06 15:05:08 +02:00
qnx6
quota quota: Check next/prev free block number after reading from quota file 2022-10-26 13:16:56 +02:00
ramfs
reiserfs reiserfs: check directory items on read from disk 2021-08-15 13:03:33 +02:00
romfs
squashfs squashfs: fix divide error in calculate_skip() 2021-05-22 10:57:39 +02:00
sysfs fs: sysfs_emit: Remove PAGE_SIZE alignment check 2022-03-23 09:01:35 +01:00
sysv fs: sysv: Fix sysv_nblocks() returns wrong value 2023-01-18 09:26:11 +01:00
tracefs tracefs: Only clobber mode/uid/gid on remount if asked 2022-09-20 11:51:31 +02:00
ubifs ubifs: Rectify space amount budget for mkdir/tmpfile operations 2022-04-20 09:08:25 +02:00
udf udf: Fix extending file within last block 2023-01-18 09:26:06 +01:00
ufs
xfs xfs: remove incorrect ASSERT in xfs_rename 2022-07-12 16:27:28 +02:00
aio.c
anon_inodes.c
attr.c vfs: Check the truncate maximum size in inode_newsize_ok() 2022-08-25 11:11:11 +02:00
bad_inode.c
binfmt_aout.c
binfmt_elf.c
binfmt_elf_fdpic.c
binfmt_em86.c
binfmt_flat.c binfmt_flat: do not stop relocating GOT entries prematurely on riscv 2022-06-14 16:53:43 +02:00
binfmt_misc.c
binfmt_script.c
block_dev.c block: reexpand iov_iter after read/write 2021-05-22 10:57:43 +02:00
buffer.c mm: fs: initialize fsdata passed to write_begin/write_end interface 2022-11-25 17:36:55 +01:00
char_dev.c chardev: fix error handling in cdev_device_add() 2023-01-18 09:26:24 +01:00
compat.c
compat_binfmt_elf.c
compat_ioctl.c
coredump.c
dax.c
dcache.c
dcookies.c
direct-io.c
drop_caches.c
eventfd.c
eventpoll.c
exec.c exec: Force single empty string when argv is empty 2022-06-06 08:20:57 +02:00
fcntl.c
fhandle.c
file.c fget: clarify and improve __fget_files() implementation 2022-03-02 11:34:00 +01:00
file_table.c fs: add fget_many() and fput_many() 2021-12-08 08:46:55 +01:00
filesystems.c
fs-writeback.c fs-writeback: writeback_sb_inodes:Recalculate 'wrote' according skipped pages 2022-06-14 16:53:52 +02:00
fs_pin.c
fs_struct.c
inode.c fs: fix UAF/GPF bug in nilfs_mdt_destroy 2022-10-26 13:16:51 +02:00
internal.h
ioctl.c
iomap.c
Kconfig
Kconfig.binfmt
libfs.c libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value 2023-01-18 09:26:10 +01:00
locks.c
Makefile
mbcache.c
mount.h
mpage.c
namei.c mm: fs: initialize fsdata passed to write_begin/write_end interface 2022-11-25 17:36:55 +01:00
namespace.c VFS: Fix memory leak caused by concurrently mounting fs with subtype 2022-05-15 19:40:27 +02:00
no-block.c
nsfs.c
open.c
pipe.c pipe: increase minimum default pipe size to 2 pages 2021-08-15 13:03:31 +02:00
pnode.c
pnode.h
posix_acl.c
proc_namespace.c
read_write.c
readdir.c
select.c
seq_file.c seq_file: disallow extremely large seq buffer allocations 2021-07-20 16:17:55 +02:00
signalfd.c signalfd: use wake_up_pollfree() 2021-12-14 10:16:55 +01:00
splice.c Revert "fs: check FMODE_LSEEK to control internal pipe splicing" 2022-10-26 13:16:56 +02:00
stack.c
stat.c stat: fix inconsistency between struct stat and struct compat_stat 2022-04-27 13:15:30 +02:00
statfs.c
super.c vfs: make freeze_super abort when sync_filesystem returns error 2022-02-23 11:57:33 +01:00
sync.c
timerfd.c
userfaultfd.c
utimes.c
xattr.c fs: don't audit the capability check in simple_xattr_list() 2023-01-18 09:26:09 +01:00