logger: introduce struct logger_set_tag
authorŁukasz Stelmach <l.stelmach@samsung.com>
Wed, 14 Apr 2021 15:50:51 +0000 (17:50 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 22 Apr 2021 13:46:17 +0000 (15:46 +0200)
Introduce dedicated structure for LOGGER_SET_TAG ioctl,
instead of packing and unpacking arguments by hand.

Change-Id: Ic3399ab37f55ba2b8a9a976f8c9495fc487fe7f3
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
[ Pick only changes in logger.[ch] while moving code out of tree ]
Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
drivers/staging/android/logger.c
drivers/staging/android/logger.h

index 0d21142..14fb7f7 100644 (file)
@@ -872,28 +872,30 @@ static long logger_set_prio(struct logger_writer *writer, void __user *arg)
 
 static long logger_set_tag(struct logger_writer *writer, void __user *arg)
 {
+       struct logger_set_tag tag;
        int len;
        char *p, *q;
 
-       if (copy_from_user(&len, arg, sizeof(int)))
+       if (copy_from_user(&tag, arg, sizeof(struct logger_set_tag)))
                return -EFAULT;
 
-       arg += sizeof(int);
-
+       if (tag.len > LOGGER_ENTRY_MAX_PAYLOAD)
+               return -EINVAL;
 
-       p = kzalloc(len, GFP_KERNEL);
+       p = kzalloc(tag.len, GFP_KERNEL);
        if (!p)
                return -ENOMEM;
 
-       if (copy_from_user(p, arg, len)) {
+       if (copy_from_user(p, (void*)(uintptr_t)tag.ptr, tag.len)) {
                kfree(p);
                return -EFAULT;
        }
-       p[len-1] = '\0';
+       p[tag.len - 1] = '\0';
+       len = strlen(p);
 
        q = writer->tag;
        writer->tag = p;
-       writer->tag_len = len - 1; /* without NULL */
+       writer->tag_len = len;
        kfree(q);
 
        return 0;
index a02ac11..8054a3e 100644 (file)
@@ -74,6 +74,16 @@ struct logger_entry {
        char            msg[0];
 };
 
+/**
+ * struct logger_set_tag
+ * @len:       Length of a NULL-terminated tag including '\0'
+ * @ptr:       Pointer to a user buffer containing the tag
+ */
+struct logger_set_tag {
+       __u64           len;
+       __u64           ptr;
+};
+
 #define LOGGER_LOG_RADIO       "log_radio"     /* radio-related messages */
 #define LOGGER_LOG_EVENTS      "log_events"    /* system/hardware events */
 #define LOGGER_LOG_SYSTEM      "log_system"    /* system/framework messages */