>From d99831e07917744485eed11d40befa50443b6529 Mon Sep 17 00:00:00 2001 From: Ken Mills <[email protected]> Date: Mon, 18 Oct 2010 18:27:16 -0700 Subject: [PATCH 2/4] Allow user space log messages > 8192 bytes.
Signed-off-by: Ken Mills <[email protected]> --- drivers/misc/pti.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 files changed, 30 insertions(+), 22 deletions(-) diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c index 174a87d..4be6b0c 100644 --- a/drivers/misc/pti.c +++ b/drivers/misc/pti.c @@ -47,6 +47,7 @@ #define CONSOLE_ID 73 /* console master ID address */ #define OS_BASE_ID 72 /* base OS master ID address */ #define APP_BASE_ID 80 /* base App master ID address */ +#define USER_COPY_SIZE 8192 /* 8Kb buffer to copy data from user space */ struct pti_tty { struct masterchannel *mc; @@ -508,37 +509,44 @@ int pti_char_release(struct inode *inode, struct file *filp) ssize_t pti_char_write(struct file *filp, const char *data, size_t len, loff_t *ppose) { - int retval; - struct masterchannel *mc; void *kbuf; + const char *tmp = data; + size_t size; - /* - adding a limit on the size of the buffer, since this - is a value that can be passed in by a user and we want to - minimize the chance of crashing alloc. Returning - EMSGSIZE actually seems to be the best error code - for a user to figure out what happened. - */ - if (len > 8192) - return -EMSGSIZE; + if (len <= USER_COPY_SIZE) + kbuf = kmalloc(len, GFP_KERNEL); + else + kbuf = kmalloc(USER_COPY_SIZE, GFP_KERNEL); + + if (kbuf == NULL) { + pr_err("%s(%d): buf allocation failed\n", + __func__, __LINE__); + return -ENOMEM; + } mc = filp->private_data; - kbuf = kmalloc(len, GFP_KERNEL); - if (kbuf == NULL) - return 0; - retval = copy_from_user(kbuf, data, len); - if (retval) { - kfree(kbuf); - return -EFAULT; - } + do { + if (len <= USER_COPY_SIZE) + size = len; + else + size = USER_COPY_SIZE; + + if (copy_from_user(kbuf, tmp, size)) { + kfree(kbuf); + return -EFAULT; + } + pr_debug("%s(%d): writing %u bytes\n", __func__, __LINE__, + size); + pti_write_to_aperture(mc, kbuf, size); + len -= size; + tmp += size; + + } while (len >= 0); - pr_debug("%s(%d): buf: %s, len: %d\n", __func__, __LINE__, data, len); - pti_write_to_aperture(mc, kbuf, len); kfree(kbuf); kbuf = 0; - return len; } -- 1.7.0.4
From d99831e07917744485eed11d40befa50443b6529 Mon Sep 17 00:00:00 2001 From: Ken Mills <[email protected]> Date: Mon, 18 Oct 2010 18:27:16 -0700 Subject: [PATCH 2/4] Allow user space log messages > 8192 bytes. Signed-off-by: Ken Mills <[email protected]> --- drivers/misc/pti.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 files changed, 30 insertions(+), 22 deletions(-) diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c index 174a87d..4be6b0c 100644 --- a/drivers/misc/pti.c +++ b/drivers/misc/pti.c @@ -47,6 +47,7 @@ #define CONSOLE_ID 73 /* console master ID address */ #define OS_BASE_ID 72 /* base OS master ID address */ #define APP_BASE_ID 80 /* base App master ID address */ +#define USER_COPY_SIZE 8192 /* 8Kb buffer to copy data from user space */ struct pti_tty { struct masterchannel *mc; @@ -508,37 +509,44 @@ int pti_char_release(struct inode *inode, struct file *filp) ssize_t pti_char_write(struct file *filp, const char *data, size_t len, loff_t *ppose) { - int retval; - struct masterchannel *mc; void *kbuf; + const char *tmp = data; + size_t size; - /* - adding a limit on the size of the buffer, since this - is a value that can be passed in by a user and we want to - minimize the chance of crashing alloc. Returning - EMSGSIZE actually seems to be the best error code - for a user to figure out what happened. - */ - if (len > 8192) - return -EMSGSIZE; + if (len <= USER_COPY_SIZE) + kbuf = kmalloc(len, GFP_KERNEL); + else + kbuf = kmalloc(USER_COPY_SIZE, GFP_KERNEL); + + if (kbuf == NULL) { + pr_err("%s(%d): buf allocation failed\n", + __func__, __LINE__); + return -ENOMEM; + } mc = filp->private_data; - kbuf = kmalloc(len, GFP_KERNEL); - if (kbuf == NULL) - return 0; - retval = copy_from_user(kbuf, data, len); - if (retval) { - kfree(kbuf); - return -EFAULT; - } + do { + if (len <= USER_COPY_SIZE) + size = len; + else + size = USER_COPY_SIZE; + + if (copy_from_user(kbuf, tmp, size)) { + kfree(kbuf); + return -EFAULT; + } + pr_debug("%s(%d): writing %u bytes\n", __func__, __LINE__, + size); + pti_write_to_aperture(mc, kbuf, size); + len -= size; + tmp += size; + + } while (len >= 0); - pr_debug("%s(%d): buf: %s, len: %d\n", __func__, __LINE__, data, len); - pti_write_to_aperture(mc, kbuf, len); kfree(kbuf); kbuf = 0; - return len; } -- 1.7.0.4
_______________________________________________ Meego-kernel mailing list [email protected] http://lists.meego.com/listinfo/meego-kernel
