Skip to content

Commit 2c25575

Browse files
committed
Remove redundant code
Remove unnecessary definition of SUCCESS, as returning 0 already indicates successful execution.
1 parent e061eaf commit 2c25575

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

examples/chardev.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ static ssize_t device_read(struct file *, char __user *, size_t, loff_t *);
2525
static ssize_t device_write(struct file *, const char __user *, size_t,
2626
loff_t *);
2727

28-
#define SUCCESS 0
2928
#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */
3029
#define BUF_LEN 80 /* Max length of the message from the device */
3130

@@ -72,7 +71,7 @@ static int __init chardev_init(void)
7271

7372
pr_info("Device created on /dev/%s\n", DEVICE_NAME);
7473

75-
return SUCCESS;
74+
return 0;
7675
}
7776

7877
static void __exit chardev_exit(void)
@@ -99,7 +98,7 @@ static int device_open(struct inode *inode, struct file *file)
9998
sprintf(msg, "I already told you %d times Hello world!\n", counter++);
10099
try_module_get(THIS_MODULE);
101100

102-
return SUCCESS;
101+
return 0;
103102
}
104103

105104
/* Called when a process closes the device file. */
@@ -113,7 +112,7 @@ static int device_release(struct inode *inode, struct file *file)
113112
*/
114113
module_put(THIS_MODULE);
115114

116-
return SUCCESS;
115+
return 0;
117116
}
118117

119118
/* Called when a process, which already opened the dev file, attempts to

examples/chardev2.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <asm/errno.h>
1818

1919
#include "chardev.h"
20-
#define SUCCESS 0
2120
#define DEVICE_NAME "char_dev"
2221
#define BUF_LEN 80
2322

@@ -42,15 +41,15 @@ static int device_open(struct inode *inode, struct file *file)
4241
pr_info("device_open(%p)\n", file);
4342

4443
try_module_get(THIS_MODULE);
45-
return SUCCESS;
44+
return 0;
4645
}
4746

4847
static int device_release(struct inode *inode, struct file *file)
4948
{
5049
pr_info("device_release(%p,%p)\n", inode, file);
5150

5251
module_put(THIS_MODULE);
53-
return SUCCESS;
52+
return 0;
5453
}
5554

5655
/* This function is called whenever a process which has already opened the
@@ -126,7 +125,7 @@ device_ioctl(struct file *file, /* ditto */
126125
unsigned long ioctl_param)
127126
{
128127
int i;
129-
long ret = SUCCESS;
128+
long ret = 0;
130129

131130
/* We don't want to talk to two processes at the same time. */
132131
if (atomic_cmpxchg(&already_open, CDEV_NOT_USED, CDEV_EXCLUSIVE_OPEN))

0 commit comments

Comments
 (0)