Re: [PATCH] net: cosa: fix error check return value of register_chrdev()

From: Jan Kasprzak
Date: Tue Apr 19 2022 - 04:37:51 EST


Acked-By: Jan "Yenya" Kasprzak <kas@xxxxxxxxxx>

Thanks!

-Yenya

cgel.zte@xxxxxxxxx wrote:
: From: Lv Ruyi <lv.ruyi@xxxxxxxxxx>
:
: If major equal 0, register_chrdev() returns error code when it fails.
: This function dynamically allocate a major and return its number on
: success, so we should use "< 0" to check it instead of "!".
:
: Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
: Signed-off-by: Lv Ruyi <lv.ruyi@xxxxxxxxxx>
: ---
: drivers/net/wan/cosa.c | 2 +-
: 1 file changed, 1 insertion(+), 1 deletion(-)
:
: diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
: index 23d2954d9747..1e5672019922 100644
: --- a/drivers/net/wan/cosa.c
: +++ b/drivers/net/wan/cosa.c
: @@ -349,7 +349,7 @@ static int __init cosa_init(void)
: }
: } else {
: cosa_major = register_chrdev(0, "cosa", &cosa_fops);
: - if (!cosa_major) {
: + if (cosa_major < 0) {
: pr_warn("unable to register chardev\n");
: err = -EIO;
: goto out;
: --
: 2.25.1
:

--
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| http://www.fi.muni.cz/~kas/ GPG: 4096R/A45477D5 |
We all agree on the necessity of compromise. We just can't agree on
when it's necessary to compromise. --Larry Wall