mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dtor_core@ameritech.net>
To: Vojtech Pavlik <vojtech@suse.cz>
Cc: linux-kernel@vger.kernel.org
Subject: [patch 08/24] input: make name, phys and uniq const char
Date: Mon, 25 Jul 2005 00:34:57 -0500	[thread overview]
Message-ID: <20050725054531.737563000.dtor_core@ameritech.net> (raw)
In-Reply-To: <20050725053449.483098000.dtor_core@ameritech.net>

[-- Attachment #1: input-make-name-const.patch --]
[-- Type: text/plain, Size: 4948 bytes --]

Input: make name, phys and uniq be 'const char *' because once
       set noone should attempt to change them.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 drivers/char/sonypi.c       |   24 ++----------------------
 drivers/input/misc/uinput.c |   23 ++++++++++++-----------
 include/linux/input.h       |    6 +++---
 3 files changed, 17 insertions(+), 36 deletions(-)

Index: work/drivers/char/sonypi.c
===================================================================
--- work.orig/drivers/char/sonypi.c
+++ work/drivers/char/sonypi.c
@@ -1228,14 +1228,7 @@ static int __devinit sonypi_probe(void)
 		sonypi_device.input_jog_dev.keybit[LONG(BTN_MOUSE)] =
 			BIT(BTN_MIDDLE);
 		sonypi_device.input_jog_dev.relbit[0] = BIT(REL_WHEEL);
-		sonypi_device.input_jog_dev.name =
-			kmalloc(sizeof(SONYPI_JOG_INPUTNAME), GFP_KERNEL);
-		if (!sonypi_device.input_jog_dev.name) {
-			printk(KERN_ERR "sonypi: kmalloc failed\n");
-			ret = -ENOMEM;
-			goto out_inkmallocinput1;
-		}
-		sprintf(sonypi_device.input_jog_dev.name, SONYPI_JOG_INPUTNAME);
+		sonypi_device.input_jog_dev.name = SONYPI_JOG_INPUTNAME;
 		sonypi_device.input_jog_dev.id.bustype = BUS_ISA;
 		sonypi_device.input_jog_dev.id.vendor = PCI_VENDOR_ID_SONY;
 
@@ -1249,14 +1242,7 @@ static int __devinit sonypi_probe(void)
 			if (sonypi_inputkeys[i].inputev)
 				set_bit(sonypi_inputkeys[i].inputev,
 					sonypi_device.input_key_dev.keybit);
-		sonypi_device.input_key_dev.name =
-			kmalloc(sizeof(SONYPI_KEY_INPUTNAME), GFP_KERNEL);
-		if (!sonypi_device.input_key_dev.name) {
-			printk(KERN_ERR "sonypi: kmalloc failed\n");
-			ret = -ENOMEM;
-			goto out_inkmallocinput2;
-		}
-		sprintf(sonypi_device.input_key_dev.name, SONYPI_KEY_INPUTNAME);
+		sonypi_device.input_key_dev.name = SONYPI_KEY_INPUTNAME;
 		sonypi_device.input_key_dev.id.bustype = BUS_ISA;
 		sonypi_device.input_key_dev.id.vendor = PCI_VENDOR_ID_SONY;
 
@@ -1314,11 +1300,7 @@ out_platformdev:
 	kfifo_free(sonypi_device.input_fifo);
 out_infifo:
 	input_unregister_device(&sonypi_device.input_key_dev);
-	kfree(sonypi_device.input_key_dev.name);
-out_inkmallocinput2:
 	input_unregister_device(&sonypi_device.input_jog_dev);
-	kfree(sonypi_device.input_jog_dev.name);
-out_inkmallocinput1:
 	free_irq(sonypi_device.irq, sonypi_irq);
 out_reqirq:
 	release_region(sonypi_device.ioport1, sonypi_device.region_size);
@@ -1345,9 +1327,7 @@ static void __devexit sonypi_remove(void
 
 	if (useinput) {
 		input_unregister_device(&sonypi_device.input_key_dev);
-		kfree(sonypi_device.input_key_dev.name);
 		input_unregister_device(&sonypi_device.input_jog_dev);
-		kfree(sonypi_device.input_jog_dev.name);
 		kfifo_free(sonypi_device.input_fifo);
 	}
 
Index: work/include/linux/input.h
===================================================================
--- work.orig/include/linux/input.h
+++ work/include/linux/input.h
@@ -811,9 +811,9 @@ struct input_dev {
 
 	void *private;
 
-	char *name;
-	char *phys;
-	char *uniq;
+	const char *name;
+	const char *phys;
+	const char *uniq;
 	struct input_id id;
 
 	unsigned long evbit[NBITS(EV_MAX)];
Index: work/drivers/input/misc/uinput.c
===================================================================
--- work.orig/drivers/input/misc/uinput.c
+++ work/drivers/input/misc/uinput.c
@@ -251,6 +251,7 @@ static int uinput_alloc_device(struct fi
 	struct uinput_user_dev	*user_dev;
 	struct input_dev	*dev;
 	struct uinput_device	*udev;
+	char			*name;
 	int			size;
 	int			retval;
 
@@ -274,13 +275,13 @@ static int uinput_alloc_device(struct fi
 		kfree(dev->name);
 
 	size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1;
-	dev->name = kmalloc(size, GFP_KERNEL);
-	if (!dev->name) {
+	dev->name = name = kmalloc(size, GFP_KERNEL);
+	if (!name) {
 		retval = -ENOMEM;
 		goto exit;
 	}
+	strlcpy(name, user_dev->name, size);
 
-	strlcpy(dev->name, user_dev->name, size);
 	dev->id.bustype	= user_dev->id.bustype;
 	dev->id.vendor	= user_dev->id.vendor;
 	dev->id.product	= user_dev->id.product;
@@ -397,6 +398,7 @@ static int uinput_ioctl(struct inode *in
 	struct uinput_ff_erase  ff_erase;
 	struct uinput_request   *req;
 	int                     length;
+	char			*phys;
 
 	udev = file->private_data;
 
@@ -494,20 +496,19 @@ static int uinput_ioctl(struct inode *in
 				retval = -EFAULT;
 				break;
 			}
-			if (NULL != udev->dev->phys)
-				kfree(udev->dev->phys);
-			udev->dev->phys = kmalloc(length, GFP_KERNEL);
-			if (!udev->dev->phys) {
+			kfree(udev->dev->phys);
+			udev->dev->phys = phys = kmalloc(length, GFP_KERNEL);
+			if (!phys) {
 				retval = -ENOMEM;
 				break;
 			}
-			if (copy_from_user(udev->dev->phys, p, length)) {
-				retval = -EFAULT;
-				kfree(udev->dev->phys);
+			if (copy_from_user(phys, p, length)) {
 				udev->dev->phys = NULL;
+				kfree(phys);
+				retval = -EFAULT;
 				break;
 			}
-			udev->dev->phys[length - 1] = '\0';
+			phys[length - 1] = '\0';
 			break;
 
 		case UI_BEGIN_FF_UPLOAD:


  parent reply	other threads:[~2005-07-25  5:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-25  5:34 [patch 00/24] Input patches for 2.6.13 Dmitry Torokhov
2005-07-25  5:34 ` [patch 01/24] uinput: formatting, cleanup Dmitry Torokhov
2005-07-25  5:34 ` [patch 02/24] uinput: use completions Dmitry Torokhov
2005-07-25  5:34 ` [patch 03/24] serio: add modalias Dmitry Torokhov
2005-07-25  5:34 ` [patch 04/24] Acecad: small cleanup Dmitry Torokhov
2005-07-25  5:34 ` [patch 05/24] Add usb_to_input_id Dmitry Torokhov
2005-07-25  5:34 ` [patch 06/24] sonypi: make sure input_work is not running when unloading Dmitry Torokhov
2005-07-25  5:34 ` [patch 07/24] input: rearrange procfs code Dmitry Torokhov
2005-07-25  5:34 ` Dmitry Torokhov [this message]
2005-07-25  5:34 ` [patch 09/24] input.c section fix Dmitry Torokhov
2005-07-25  5:34 ` [patch 10/24] serio_raw: link misc device and serio port Dmitry Torokhov
2005-07-25  5:35 ` [patch 11/24] serio_raw - fix Kconfig help Dmitry Torokhov
2005-07-25  5:35 ` [patch 12/24] i8042 - add Alienware Sentia to NOMUX blacklist Dmitry Torokhov
2005-07-25  5:35 ` [patch 13/24] i8042 - add Fujitsu T3010 " Dmitry Torokhov
2005-07-25  5:35 ` [patch 14/24] synaptics - limit rate on Toshiba Dynabooks Dmitry Torokhov
2005-07-25  5:35 ` [patch 15/24] ALPS: Fix resume for DualPoints Dmitry Torokhov
2005-07-25  5:35 ` [patch 16/24] ALPS: fix enabling tapping mode Dmitry Torokhov
2005-07-25  5:35 ` [patch 17/24] HID: Add a quirk for Aashima gamepad Dmitry Torokhov
2005-07-25  5:35 ` [patch 18/24] joydev - remove MSECS macro Dmitry Torokhov
2005-07-25  5:35 ` [patch 19/24] elo - fix help in Kconfig Dmitry Torokhov
2005-07-25  5:35 ` [patch 20/24] HID - only report events coming from interrupts to hiddev Dmitry Torokhov
2005-07-25  5:35 ` [patch 21/24] psmouse: wheel mice always have middle button Dmitry Torokhov
2005-07-25  5:35 ` [patch 22/24] i8042 - dont use negation in i8042_command() Dmitry Torokhov
2005-07-25  5:35 ` [patch 23/24] Input - check keycodesize when adjusting keymaps Dmitry Torokhov
2005-07-25  5:35 ` [patch 24/24] Synaptics - fix setting packet size on passthrough port Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050725054531.737563000.dtor_core@ameritech.net \
    --to=dtor_core@ameritech.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vojtech@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®