printk: Remove obsoleted check for non-existent "user" object
Commit Message
From: Stanislav Kinsburskii <stanislav.kinsburski@gmail.com>
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 <stanislav.kinsburski@gmail.com>
CC: Petr Mladek <pmladek@suse.com>
CC: Sergey Senozhatsky <senozhatsky@chromium.org>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: John Ogness <john.ogness@linutronix.de>
CC: linux-kernel@vger.kernel.org
---
kernel/printk/printk.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
Comments
On (23/03/20 00:02), Stanislav Kinsburskii wrote:
> From: Stanislav Kinsburskii <stanislav.kinsburski@gmail.com>
>
> 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 <stanislav.kinsburski@gmail.com>
> CC: Petr Mladek <pmladek@suse.com>
> CC: Sergey Senozhatsky <senozhatsky@chromium.org>
> CC: Steven Rostedt <rostedt@goodmis.org>
> CC: John Ogness <john.ogness@linutronix.de>
> CC: linux-kernel@vger.kernel.org
Looks like we should be fine
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
On Mon 2023-03-20 00:02:01, Stanislav Kinsburskii wrote:
> From: Stanislav Kinsburskii <stanislav.kinsburski@gmail.com>
>
> 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 <stanislav.kinsburski@gmail.com>
Yup, it looks safe.
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
On Mon 2023-03-20 00:02:01, Stanislav Kinsburskii wrote:
> From: Stanislav Kinsburskii <stanislav.kinsburski@gmail.com>
>
> 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 <stanislav.kinsburski@gmail.com>
JFYI, the patch has been committed into, printk/linux.git,
branch for-6.4.
Best Regards,
Petr
@@ -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);