From: Andrew Morton <akpm@osdl.org> - Dink with whitespace a bit - Use ARRAY_SIZE - Wow, yealink.h includes itself! Cc: Henk <Henk.Vergonet@gmail.com> Cc: Greg KH <greg@kroah.com> Cc: Vojtech Pavlik <vojtech@suse.cz> Cc: Dmitry Torokhov <dtor_core@ameritech.net> Signed-off-by: Andrew Morton <akpm@osdl.org> --- drivers/usb/input/yealink.c | 81 ++++++++++++++++++++++---------------------- input/yealink.txt | 0 usb/input/Kconfig | 0 usb/input/Makefile | 0 usb/input/map_to_7segment.h | 0 usb/input/yealink.h | 0 6 files changed, 42 insertions(+), 39 deletions(-) diff -puN Documentation/input/yealink.txt~new-driver-for-yealink-usb-p1k-phone-tidy Documentation/input/yealink.txt diff -puN drivers/usb/input/Kconfig~new-driver-for-yealink-usb-p1k-phone-tidy drivers/usb/input/Kconfig diff -puN drivers/usb/input/Makefile~new-driver-for-yealink-usb-p1k-phone-tidy drivers/usb/input/Makefile diff -puN drivers/usb/input/map_to_7segment.h~new-driver-for-yealink-usb-p1k-phone-tidy drivers/usb/input/map_to_7segment.h diff -puN drivers/usb/input/yealink.c~new-driver-for-yealink-usb-p1k-phone-tidy drivers/usb/input/yealink.c --- 25/drivers/usb/input/yealink.c~new-driver-for-yealink-usb-p1k-phone-tidy 2005-06-25 02:29:58.000000000 -0700 +++ 25-akpm/drivers/usb/input/yealink.c 2005-06-25 02:36:08.000000000 -0700 @@ -147,27 +147,25 @@ static int setChar(struct yealink_dev *y if (lcdMap[el].type == '.') { a = lcdMap[el].u.p.a; m = lcdMap[el].u.p.m; - if (chr != ' ') { + if (chr != ' ') yld->master.b[a] |= m; - } else { + else yld->master.b[a] &= ~m; - } return 0; } val = map_to_seg7(&map_seg7, chr); - for(i=0; i<sizeof(lcdMap[0].u.s)/sizeof(lcdMap[0].u.s[0]); i++) { + for (i = 0; i < ARRAY_SIZE(lcdMap[0].u.s); i++) { m = lcdMap[el].u.s[i].m; if (m == 0) continue; a = lcdMap[el].u.s[i].a; - if (val & 1) { + if (val & 1) yld->master.b[a] |= m; - } else { + else yld->master.b[a] &= ~m; - } val = val >> 1; } return 0; @@ -245,7 +243,7 @@ static void report_key(struct yealink_de input_report_key(idev, key & 0xff, 1); if (key >> 8) input_report_key(idev, key >> 8, 1); - }; + } input_sync(idev); } @@ -263,12 +261,12 @@ static int yealink_do_idle_tasks(struct memcpy(buf, cmd_KEYPRESS, USB_PKT_LEN); yld->idle_repeat--; - if(yld->idle_repeat < 0) + if (yld->idle_repeat < 0) return 0; /* find update candidates */ - for (i=0; i<sizeof(yld->master); i++) { + for (i = 0; i < sizeof(yld->master); i++) { ix = (yld->stat_ix + i) % sizeof(yld->master); if (yld->master.b[ix] != yld->copy.b[ix]) goto update; @@ -285,7 +283,7 @@ update: buf[15] -= val; } else if (ix == offsetof(struct yld_status, led)) { memcpy(buf, cmd_LED_USB, USB_PKT_LEN); - if(val) { + if (val) { buf[3] = 0x0; buf[4] = 0xff; } @@ -371,7 +369,7 @@ static int yealink_state_machine(struct ntohl(*(u32 *)&yld->irq_data[12])); } - return usb_submit_urb (yld->urb_ctl, GFP_ATOMIC); + return usb_submit_urb(yld->urb_ctl, GFP_ATOMIC); } static void urb_irq_callback(struct urb *urb, struct pt_regs *regs) @@ -391,7 +389,8 @@ static void urb_irq_callback(struct urb __FUNCTION__, urb->status); return; default: - dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); + dbg("%s - nonzero urb status received: %d", + __FUNCTION__, urb->status); *(u16 *)yld->irq_data = 0; /* restart keyboard */ } @@ -406,11 +405,11 @@ static void urb_ctl_callback(struct urb int ret; if (urb->status) - err ("config urb returned %d", urb->status); + err("config urb returned %d", urb->status); - ret = usb_submit_urb (yld->urb_irq, GFP_ATOMIC); + ret = usb_submit_urb(yld->urb_irq, GFP_ATOMIC); if (ret) - err ("%s - usb_submit_urb irq failed %d", + err("%s - usb_submit_urb irq failed %d", __FUNCTION__, ret); } @@ -419,7 +418,7 @@ static void urb_ctl_callback(struct urb ******************************************************************************/ // TODO should we issue a ringtone on a SND_BELL event? -static int input_ev (struct input_dev *dev, unsigned int type, +static int input_ev(struct input_dev *dev, unsigned int type, unsigned int code, int value) { // struct yealink_dev *yld = dev->private; @@ -438,7 +437,7 @@ static int input_ev (struct input_dev *d return 0; } -static int input_open (struct input_dev *dev) +static int input_open(struct input_dev *dev) { struct yealink_dev *yld = dev->private; int i, ret; @@ -449,7 +448,7 @@ static int input_open (struct input_dev return 0; /* force updates to device */ - for (i=0; i<sizeof(yld->master); i++) + for (i = 0; i<sizeof(yld->master); i++) yld->copy.b[i] = ~yld->master.b[i]; yld->key_code = -1;; @@ -459,7 +458,7 @@ static int input_open (struct input_dev /* issue INIT */ memcpy(yld->ctl_data, cmd_INIT, USB_PKT_LEN); if ((ret = usb_submit_urb(yld->urb_ctl, GFP_KERNEL)) != 0) { - dbg ("%s - usb_submit_urb failed with result %d", + dbg("%s - usb_submit_urb failed with result %d", __FUNCTION__, ret); yld->open_count--; return ret; @@ -467,7 +466,7 @@ static int input_open (struct input_dev return 0; } -static void input_close (struct input_dev *dev) +static void input_close(struct input_dev *dev) { struct yealink_dev *yld = dev->private; @@ -487,6 +486,7 @@ static ssize_t show_map(struct device *d memcpy(buf, &map_seg7, sizeof(map_seg7)); return sizeof(map_seg7); } + static ssize_t store_map(struct device *dev, const char *buf, size_t cnt) { memcpy(&map_seg7, buf, cnt > sizeof(map_seg7) ? sizeof(map_seg7) : cnt); @@ -506,15 +506,16 @@ static ssize_t store_map(struct device * static ssize_t show_line(char *buf, int a, int b) { int i = 0; - for (i=a; i<b; i++) + for (i = a; i < b; i++) *buf++ = lcdMap[i].type; *buf++ = '\n'; - for (i=a; i<b; i++) + for (i = a; i < b; i++) *buf++ = lcdMap[i].value; *buf++ = '\n'; *buf = 0; return 3 + ((b - a) << 1); } + static ssize_t show_line1(struct device *dev, char *buf) { return show_line(buf, LCD_LINE1_OFFSET, LCD_LINE2_OFFSET); } static ssize_t show_line2(struct device *dev, char *buf) @@ -540,10 +541,11 @@ static ssize_t store_line(struct device if (len > count) len = count; - for (i=0; i<len; i++) + for (i = 0; i < len; i++) setChar(yld, el++, buf[i]); return count; } + static ssize_t store_line1(struct device *dev, const char *buf, size_t count) { return store_line(dev, buf, count, LCD_LINE1_OFFSET, LCD_LINE1_SIZE); } static ssize_t store_line2(struct device *dev, const char *buf, size_t count) @@ -559,7 +561,7 @@ static ssize_t store_line3(struct device static ssize_t get_icons(struct device *dev, char *buf) { int i, ret = 1; - for (i=0; i<sizeof(lcdMap)/sizeof(lcdMap[0]); i++) { + for (i = 0; i < ARRAY_SIZE(lcdMap); i++) { if (lcdMap[i].type != '.') continue; ret += sprintf(&buf[ret], "%s %s\n", @@ -571,24 +573,24 @@ static ssize_t get_icons(struct device * /* Change the visibility of a particular element. */ static ssize_t set_icon(struct device *dev, const char *buf, size_t count, - int chr) + int chr) { struct yealink_dev *yld = dev_get_drvdata(dev); int i; if (yld == NULL) return count; - for (i=0; i<sizeof(lcdMap)/sizeof(lcdMap[0]); i++) { + for (i = 0; i < ARRAY_SIZE(lcdMap); i++) { if (lcdMap[i].type != '.') continue; - if (strncmp(buf, lcdMap[i].u.p.name, count) == 0) - { + if (strncmp(buf, lcdMap[i].u.p.name, count) == 0) { setChar(yld, i, chr); break; } } return count; } + static ssize_t show_icon(struct device *dev, const char *buf, size_t count) { return set_icon(dev, buf, count, buf[0]); } static ssize_t hide_icon(struct device *dev, const char *buf, size_t count) @@ -601,10 +603,12 @@ static ssize_t get_ringtone(struct devic returns a list of available ringtones, with an indication of the currently selected one. } + static ssize_t set_ringtone(struct device *dev, const char *buf, size_t count) { sets the a ringtone. } + static DEVICE_ATTR(ringtone, S_IRUGO|S_IWUSR|S_IWGRP, get_ringtone, set_ringtone); */ @@ -632,7 +636,7 @@ static int create_sysfs_files(struct dev struct yealink_dev *yld = dev_get_drvdata(dev); int i, ret; - for (i=0; i<sizeof(lcdMap)/sizeof(lcdMap[0]); i++) + for (i = 0; i < ARRAY_SIZE(lcdMap); i++) setChar(yld, i, lcdMap[i].value); store_line3(dev, DRIVER_VERSION, sizeof(DRIVER_VERSION)); if ( (ret = device_create_file(dev, &dev_attr_line1)) || @@ -692,8 +696,9 @@ static int usb_cleanup(struct yealink_de return err; } -static void usb_disconnect(struct usb_interface *intf) { - struct yealink_dev *yld = usb_get_intfdata (intf); +static void usb_disconnect(struct usb_interface *intf) +{ + struct yealink_dev *yld = usb_get_intfdata(intf); usb_set_intfdata(intf, NULL); remove_sysfs_files(&intf->dev); @@ -710,7 +715,7 @@ static int usb_probe(struct usb_interfac int ret, pipe, i; /* test for vendor */ - for (i=0; i<sizeof(yld_device)/sizeof(yld_device[0]); i++) { + for (i = 0; i < ARRAY_SIZE(yld_device); i++) { if ((udev->descriptor.idVendor == yld_device[i].idVendor) && (udev->descriptor.idProduct == yld_device[i].idProduct)) goto device_found; @@ -729,7 +734,7 @@ device_found: if ((yld = kmalloc(sizeof(struct yealink_dev), GFP_KERNEL)) == NULL) return -ENOMEM; - memset(yld, 0, sizeof(struct yealink_dev)); + memset(yld, 0, sizeof(*yld)); yld->udev = udev; /* allocate usb buffers */ @@ -760,9 +765,8 @@ device_found: /* get a handle to the interrupt data pipe */ pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); ret = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); - if (ret != USB_PKT_LEN) { + if (ret != USB_PKT_LEN) err("invalid payload size %d, expected %d", ret, USB_PKT_LEN); - } /* initialise irq urb */ usb_fill_int_urb(yld->urb_irq, udev, pipe, yld->irq_data, @@ -790,9 +794,8 @@ device_found: URB_NO_TRANSFER_DMA_MAP; /* find out the physical bus location */ - if (usb_make_path(udev, path, sizeof(path)) > 0) { + if (usb_make_path(udev, path, sizeof(path)) > 0) snprintf(yld->phys, sizeof(yld->phys)-1, "%s/input0", path); - } /* register settings for the input device */ init_input_dev(&yld->idev); @@ -810,7 +813,7 @@ device_found: /* register available key events */ yld->idev.evbit[0] = BIT(EV_KEY); - for (i=0; i<256; i++) { + for (i = 0; i < 256; i++) { int k = map_p1k_to_key(i); if (k >= 0) { set_bit(k & 0xff, yld->idev.keybit); diff -puN drivers/usb/input/yealink.h~new-driver-for-yealink-usb-p1k-phone-tidy drivers/usb/input/yealink.h _