Skip to content

Commit

Permalink
Shorten sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
jserv committed Jul 22, 2021
1 parent 52dfb67 commit 1c93f2f
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions examples/chardev2.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ static struct class *cls;
*/
static int device_open(struct inode *inode, struct file *file)
{
#ifdef DEBUG
pr_info("device_open(%p)\n", file);
#endif

/*
* We don't want to talk to two processes at the same time
Expand All @@ -64,9 +62,7 @@ static int device_open(struct inode *inode, struct file *file)

static int device_release(struct inode *inode, struct file *file)
{
#ifdef DEBUG
pr_info("device_release(%p,%p)\n", inode, file);
#endif

/*
* We're now ready for our next caller
Expand All @@ -92,9 +88,7 @@ static ssize_t device_read(struct file *file, /* see include/linux/fs.h */
*/
int bytes_read = 0;

#ifdef DEBUG
pr_info("device_read(%p,%p,%d)\n", file, buffer, length);
#endif
pr_info("device_read(%p,%p,%ld)\n", file, buffer, length);

/*
* If we're at the end of the message, return 0
Expand All @@ -119,9 +113,7 @@ static ssize_t device_read(struct file *file, /* see include/linux/fs.h */
bytes_read++;
}

#ifdef DEBUG
pr_info("Read %d bytes, %d left\n", bytes_read, length);
#endif
pr_info("Read %d bytes, %ld left\n", bytes_read, length);

/*
* Read functions are supposed to return the number
Expand All @@ -141,9 +133,7 @@ static ssize_t device_write(struct file *file,
{
int i;

#ifdef DEBUG
pr_info("device_write(%p,%s,%d)", file, buffer, length);
#endif
pr_info("device_write(%p,%s,%ld)", file, buffer, length);

for (i = 0; i < length && i < BUF_LEN; i++)
get_user(Message[i], buffer + i);
Expand Down

0 comments on commit 1c93f2f

Please sign in to comment.