2023-03-28 21:47:39

by Stanislav Kinsburskii

[permalink] [raw]
Subject: [PATCH] printk: Remove obsoleted check for non-existent "user" object

From: Stanislav Kinsburskii <[email protected]>

The original check for non-null "user" object was introduced by commit
e11fea92e13f ("kmsg: export printk records to the /dev/kmsg interface") when
"user" could be NULL if /dev/ksmg was opened for writing.

Subsequent change 750afe7babd1 ("printk: add kernel parameter to control
writes to /dev/kmsg") made "user" context required for files opened for write,
but didn't remove now redundant checks for it to be non-NULL.

This patch removes the dead code while preserving the current logic.

Signed-off-by: Stanislav Kinsburskii <[email protected]>
CC: Petr Mladek <[email protected]>
CC: Sergey Senozhatsky <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: John Ogness <[email protected]>
CC: [email protected]
---
kernel/printk/printk.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fd0c9f913940..9644f6e5bf15 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -730,7 +730,7 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from)
size_t len = iov_iter_count(from);
ssize_t ret = len;

- if (!user || len > PRINTKRB_RECORD_MAX)
+ if (len > PRINTKRB_RECORD_MAX)
return -EINVAL;

/* Ignore when user logging is disabled. */
@@ -792,9 +792,6 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
};
ssize_t ret;

- if (!user)
- return -EBADF;
-
ret = mutex_lock_interruptible(&user->lock);
if (ret)
return ret;
@@ -859,8 +856,6 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
struct devkmsg_user *user = file->private_data;
loff_t ret = 0;

- if (!user)
- return -EBADF;
if (offset)
return -ESPIPE;

@@ -893,9 +888,6 @@ static __poll_t devkmsg_poll(struct file *file, poll_table *wait)
struct printk_info info;
__poll_t ret = 0;

- if (!user)
- return EPOLLERR|EPOLLNVAL;
-
poll_wait(file, &log_wait, wait);

if (prb_read_valid_info(prb, atomic64_read(&user->seq), &info, NULL)) {
@@ -944,9 +936,6 @@ static int devkmsg_release(struct inode *inode, struct file *file)
{
struct devkmsg_user *user = file->private_data;

- if (!user)
- return 0;
-
ratelimit_state_exit(&user->rs);

mutex_destroy(&user->lock);



2023-03-31 04:14:06

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH] printk: Remove obsoleted check for non-existent "user" object

On (23/03/20 00:02), Stanislav Kinsburskii wrote:
> From: Stanislav Kinsburskii <[email protected]>
>
> The original check for non-null "user" object was introduced by commit
> e11fea92e13f ("kmsg: export printk records to the /dev/kmsg interface") when
> "user" could be NULL if /dev/ksmg was opened for writing.
>
> Subsequent change 750afe7babd1 ("printk: add kernel parameter to control
> writes to /dev/kmsg") made "user" context required for files opened for write,
> but didn't remove now redundant checks for it to be non-NULL.
>
> This patch removes the dead code while preserving the current logic.
>
> Signed-off-by: Stanislav Kinsburskii <[email protected]>
> CC: Petr Mladek <[email protected]>
> CC: Sergey Senozhatsky <[email protected]>
> CC: Steven Rostedt <[email protected]>
> CC: John Ogness <[email protected]>
> CC: [email protected]

Looks like we should be fine
Reviewed-by: Sergey Senozhatsky <[email protected]>

2023-04-03 10:15:02

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH] printk: Remove obsoleted check for non-existent "user" object

On Mon 2023-03-20 00:02:01, Stanislav Kinsburskii wrote:
> From: Stanislav Kinsburskii <[email protected]>
>
> The original check for non-null "user" object was introduced by commit
> e11fea92e13f ("kmsg: export printk records to the /dev/kmsg interface") when
> "user" could be NULL if /dev/ksmg was opened for writing.
>
> Subsequent change 750afe7babd1 ("printk: add kernel parameter to control
> writes to /dev/kmsg") made "user" context required for files opened for write,
> but didn't remove now redundant checks for it to be non-NULL.
>
> This patch removes the dead code while preserving the current logic.
>
> Signed-off-by: Stanislav Kinsburskii <[email protected]>

Yup, it looks safe.

Reviewed-by: Petr Mladek <[email protected]>

Best Regards,
Petr

2023-04-03 10:43:18

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH] printk: Remove obsoleted check for non-existent "user" object

On Mon 2023-03-20 00:02:01, Stanislav Kinsburskii wrote:
> From: Stanislav Kinsburskii <[email protected]>
>
> The original check for non-null "user" object was introduced by commit
> e11fea92e13f ("kmsg: export printk records to the /dev/kmsg interface") when
> "user" could be NULL if /dev/ksmg was opened for writing.
>
> Subsequent change 750afe7babd1 ("printk: add kernel parameter to control
> writes to /dev/kmsg") made "user" context required for files opened for write,
> but didn't remove now redundant checks for it to be non-NULL.
>
> This patch removes the dead code while preserving the current logic.
>
> Signed-off-by: Stanislav Kinsburskii <[email protected]>

JFYI, the patch has been committed into, printk/linux.git,
branch for-6.4.

Best Regards,
Petr