Re: [char_dev] Invalid uses of cdev_add return value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 07, 2023 at 07:55:28PM +0300, Roi L wrote:
> I hope I'm emailing the right place. I have recently noticed that there
> are many invalid uses of `cdev_add`'s return value in the kernel source.
> While `cdev_add` clearly mentions that it returns a negative value on
> failure, many calls to this function check the return value as a
> positive value.
> 
> E.g. (/drivers/mtd/ubi/vmt.c:581)
> ```
> err = cdev_add(&vol->cdev, dev, 1);
> if (err) {
> 	ubi_err(ubi, "cannot add character device for volume %d, error %d",
> 		vol_id, err);

OK, what you're missing is that on success, cdev_add() returns zero.
So in practice, there is no difference between 'if (err)' and
'if (err < 0)'.  Both check for an error, as err can never be positive.

I happen to think it's good practice to check for err < 0 rather than
just err, and it makes no difference at all on any CPU that I've ever
encountered.  But patches to clean it up would be unwelcome churn.

Thanks for checking rather than starting out by sending patches that
would have to be rejected!



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux