tablet: Bug fix for the kernel command breaking
authorjinhyung.jo <jinhyung.jo@samsung.com>
Tue, 27 Oct 2015 05:42:24 +0000 (14:42 +0900)
committerJinhyung Jo <jinhyung.jo@samsung.com>
Tue, 18 Oct 2016 07:50:05 +0000 (16:50 +0900)
When getting the display resolution, some parameters are missing.
Because the driver directly uses the address of the kernel command line.
So it copies the kernel command line to temporary buffer and uses it.
And added some modification for the logs.

Change-Id: If8cffbed1cbb81200bf46ade862a5f38e0c3914c
Signed-off-by: Jinhyung Jo <jinhyung.jo@samsung.com>
(cherry picked from commit 9c4925034c0d3a474c51c7760e7fdd8f3637624c)

drivers/maru/maru_virtio_tablet.c

index ef22ebccb64cb4b9440b09093f14720f50f9208f..ee8f258c1b2f6be0c33d45c6b4b84737a9f74bd3 100644 (file)
@@ -162,6 +162,8 @@ static int virtio_tablet_probe(struct virtio_device *vdev)
 {
        int ret = 0;
        char *cmdline = NULL;
+       char *str_param = NULL;
+       char *tmp = NULL;
        int width = 0;
        int height = 0;
 
@@ -213,44 +215,59 @@ static int virtio_tablet_probe(struct virtio_device *vdev)
                                | BIT_MASK(EV_ABS)
                                | BIT_MASK(EV_MSC);
 
-       cmdline = strstr(saved_command_line, CMDLINE_VIDEO_PARAM);
-       if (cmdline != NULL) {
-               char *tmp;
 
-               cmdline += strlen(CMDLINE_VIDEO_PARAM);
-               tmp = strsep(&cmdline, "x");
+       cmdline = kzalloc(strlen(saved_command_line) + 1, GFP_KERNEL);
+       if (cmdline == NULL) {
+               printk(KERN_WARNING "[%s] cannot fine the kernel command line\n",
+                       DEVICE_NAME);
+               goto default_resolution;
+       }
+
+       strcpy(cmdline, saved_command_line);
+       str_param = strstr(cmdline, CMDLINE_VIDEO_PARAM);
+       if (str_param == NULL) {
+               printk(KERN_WARNING "[%s] cannot find the video resolution(%s) "
+                       "in the kernel command line\n",
+                       DEVICE_NAME, CMDLINE_VIDEO_PARAM);
+               goto default_resolution;
+       }
+
+       str_param += strlen(CMDLINE_VIDEO_PARAM);
+       tmp = strsep(&str_param, "x");
+       if (tmp != NULL) {
+               ret = kstrtoint(tmp, 10, &width);
+               if (ret) {
+                       printk(KERN_WARNING "[%s] cannot find the width value\n",
+                               DEVICE_NAME);
+                       width = 0;
+                       goto default_resolution;
+               }
+
+               tmp = strsep(&str_param, "-");
                if (tmp != NULL) {
-                       ret = kstrtoint(tmp, 10, &width);
+                       ret = kstrtoint(tmp, 10, &height);
                        if (ret) {
-                               printk(KERN_WARNING "cannot find the width value\n");
-                               width = 0;
-                       }
-
-                       tmp = strsep(&cmdline, "-");
-                       if (tmp != NULL) {
-                               ret = kstrtoint(tmp, 10, &height);
-                               if (ret) {
-                                       printk(KERN_WARNING "cannot find the height value\n");
-                                       height = 0;
-                               }
-                       } else {
-                               printk(KERN_WARNING "Invalid bpp separator:"
-                                               " cannot find the height value\n");
+                               printk(KERN_WARNING "[%s] cannot find the height value\n",
+                                       DEVICE_NAME);
+                               height = width = 0;
+                               goto default_resolution;
                        }
                } else {
-                       printk(KERN_WARNING "Invalid resolution separator: "
-                                       " cannot find the width value\n");
+                       printk(KERN_WARNING "[%s] Invalid bpp separator:"
+                               " cannot find the height value\n", DEVICE_NAME);
                }
        } else {
-               printk(KERN_WARNING "cannot find the video parameter(%s) "
-                               "in the kernel command line\n", CMDLINE_VIDEO_PARAM);
+               printk(KERN_WARNING "[%s] Invalid resolution separator: "
+                       " cannot find the width value\n", DEVICE_NAME);
        }
 
+default_resolution:
+       kfree(cmdline);
        if (!width || !height) {
                width = DEFAULT_WIDTH;
                height = DEFAULT_HEIGHT;
-               printk(KERN_WARNING "cannot find the width or height, "
-                       "use default values %dx%d\n", width, height);
+               printk(KERN_WARNING "[%s] cannot find the width or height, "
+                       "use default values %dx%d\n", DEVICE_NAME, width, height);
        }
 
        input_set_abs_params(vtb->idev, ABS_X, 0, width, 0, 0);