Skip to content

Add error handling for class_create()#362

Merged
jserv merged 1 commit into
sysprog21:masterfrom
EricccTaiwan:err-check
Mar 4, 2026
Merged

Add error handling for class_create()#362
jserv merged 1 commit into
sysprog21:masterfrom
EricccTaiwan:err-check

Conversation

@EricccTaiwan
Copy link
Copy Markdown
Collaborator

@EricccTaiwan EricccTaiwan commented Mar 4, 2026

Check the return value of class_create() in chardev.c and chardev2.c, unregistering the char device and returning the error code if class creation fails.


Summary by cubic

Handle class_create() failures in the example char drivers to avoid leaks and return clear errors. On failure, we now unregister the char device and return PTR_ERR.

  • Bug Fixes
    • Check IS_ERR(cls) after class_create in chardev.c, chardev2.c, and static_key.c.
    • On failure: log with pr_err, unregister_chrdev, and return PTR_ERR.

Written for commit fdf50cc. Summary will update on new commits.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@jserv
Copy link
Copy Markdown
Contributor

jserv commented Mar 4, 2026

Can you confirm the similar issues have been resolved within whole example code?

Copy link
Copy Markdown
Collaborator

@visitorckw visitorckw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Check the return value of class_create(), unregistering the char
device and returning the error code if class creation fails.

Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
@EricccTaiwan
Copy link
Copy Markdown
Collaborator Author

Can you confirm the similar issues have been resolved within whole example code?

Done.

@jserv jserv merged commit e19994d into sysprog21:master Mar 4, 2026
1 check passed
@jserv
Copy link
Copy Markdown
Contributor

jserv commented Mar 4, 2026

Thank @EricccTaiwan for contributing!

@EricccTaiwan EricccTaiwan deleted the err-check branch March 4, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants