From d1d76f7efdeecc488411136905a9a327c988dc0d Mon Sep 17 00:00:00 2001 From: jeremy90307 Date: Mon, 10 Mar 2025 22:09:22 +0800 Subject: [PATCH] Remove redundant code Remove unnecessary definition of SUCCESS, as returning 0 already indicates successful execution. --- examples/chardev.c | 7 +++---- examples/chardev2.c | 7 +++---- examples/static_key.c | 7 +++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/examples/chardev.c b/examples/chardev.c index 2d788e6..3b2d67c 100644 --- a/examples/chardev.c +++ b/examples/chardev.c @@ -25,7 +25,6 @@ static ssize_t device_read(struct file *, char __user *, size_t, loff_t *); static ssize_t device_write(struct file *, const char __user *, size_t, loff_t *); -#define SUCCESS 0 #define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */ #define BUF_LEN 80 /* Max length of the message from the device */ @@ -72,7 +71,7 @@ static int __init chardev_init(void) pr_info("Device created on /dev/%s\n", DEVICE_NAME); - return SUCCESS; + return 0; } static void __exit chardev_exit(void) @@ -99,7 +98,7 @@ static int device_open(struct inode *inode, struct file *file) sprintf(msg, "I already told you %d times Hello world!\n", counter++); try_module_get(THIS_MODULE); - return SUCCESS; + return 0; } /* Called when a process closes the device file. */ @@ -113,7 +112,7 @@ static int device_release(struct inode *inode, struct file *file) */ module_put(THIS_MODULE); - return SUCCESS; + return 0; } /* Called when a process, which already opened the dev file, attempts to diff --git a/examples/chardev2.c b/examples/chardev2.c index 1cac869..0fcb63f 100644 --- a/examples/chardev2.c +++ b/examples/chardev2.c @@ -17,7 +17,6 @@ #include #include "chardev.h" -#define SUCCESS 0 #define DEVICE_NAME "char_dev" #define BUF_LEN 80 @@ -42,7 +41,7 @@ static int device_open(struct inode *inode, struct file *file) pr_info("device_open(%p)\n", file); try_module_get(THIS_MODULE); - return SUCCESS; + return 0; } static int device_release(struct inode *inode, struct file *file) @@ -50,7 +49,7 @@ static int device_release(struct inode *inode, struct file *file) pr_info("device_release(%p,%p)\n", inode, file); module_put(THIS_MODULE); - return SUCCESS; + return 0; } /* This function is called whenever a process which has already opened the @@ -126,7 +125,7 @@ device_ioctl(struct file *file, /* ditto */ unsigned long ioctl_param) { int i; - long ret = SUCCESS; + long ret = 0; /* We don't want to talk to two processes at the same time. */ if (atomic_cmpxchg(&already_open, CDEV_NOT_USED, CDEV_EXCLUSIVE_OPEN)) diff --git a/examples/static_key.c b/examples/static_key.c index 5f74f48..0bd1410 100644 --- a/examples/static_key.c +++ b/examples/static_key.c @@ -22,7 +22,6 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count, static ssize_t device_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos); -#define SUCCESS 0 #define DEVICE_NAME "key_state" #define BUF_LEN 10 @@ -71,7 +70,7 @@ static int __init chardev_init(void) pr_info("Device created on /dev/%s\n", DEVICE_NAME); - return SUCCESS; + return 0; } static void __exit chardev_exit(void) @@ -103,7 +102,7 @@ static int device_open(struct inode *inode, struct file *file) try_module_get(THIS_MODULE); - return SUCCESS; + return 0; } /** @@ -120,7 +119,7 @@ static int device_release(struct inode *inode, struct file *file) */ module_put(THIS_MODULE); - return SUCCESS; + return 0; } /**