Commit 7785925d authored by Evgeniy Polyakov's avatar Evgeniy Polyakov Committed by Greg Kroah-Hartman

[PATCH] w1: cleanups.

 - white space changes.
 - list_for_each_entry/list_for_each_entry_safe and reverse changes.
 - small coding style changes.
 - removed redundant NULL checks.
 - use attribute group and macros instead of direct device attributes.
Patch is havily based on work from Adrian Bunk and Dmitry Torokhov,
thanks guys.
Signed-off-by: default avatarEvgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 85e941cc
...@@ -3,9 +3,9 @@ menu "Dallas's 1-wire bus" ...@@ -3,9 +3,9 @@ menu "Dallas's 1-wire bus"
config W1 config W1
tristate "Dallas's 1-wire support" tristate "Dallas's 1-wire support"
---help--- ---help---
Dallas's 1-wire bus is usefull to connect slow 1-pin devices Dallas's 1-wire bus is usefull to connect slow 1-pin devices
such as iButtons and thermal sensors. such as iButtons and thermal sensors.
If you want W1 support, you should say Y here. If you want W1 support, you should say Y here.
This W1 support can also be built as a module. If so, the module This W1 support can also be built as a module. If so, the module
...@@ -17,8 +17,8 @@ config W1_MATROX ...@@ -17,8 +17,8 @@ config W1_MATROX
help help
Say Y here if you want to communicate with your 1-wire devices Say Y here if you want to communicate with your 1-wire devices
using Matrox's G400 GPIO pins. using Matrox's G400 GPIO pins.
This support is also available as a module. If so, the module This support is also available as a module. If so, the module
will be called matrox_w1.ko. will be called matrox_w1.ko.
config W1_DS9490 config W1_DS9490
...@@ -27,17 +27,17 @@ config W1_DS9490 ...@@ -27,17 +27,17 @@ config W1_DS9490
help help
Say Y here if you want to have a driver for DS9490R UWB <-> W1 bridge. Say Y here if you want to have a driver for DS9490R UWB <-> W1 bridge.
This support is also available as a module. If so, the module This support is also available as a module. If so, the module
will be called ds9490r.ko. will be called ds9490r.ko.
config W1_DS9490_BRIDGE config W1_DS9490R_BRIDGE
tristate "DS9490R USB <-> W1 transport layer for 1-wire" tristate "DS9490R USB <-> W1 transport layer for 1-wire"
depends on W1_DS9490 depends on W1_DS9490
help help
Say Y here if you want to communicate with your 1-wire devices Say Y here if you want to communicate with your 1-wire devices
using DS9490R USB bridge. using DS9490R USB bridge.
This support is also available as a module. If so, the module This support is also available as a module. If so, the module
will be called ds_w1_bridge.ko. will be called ds_w1_bridge.ko.
config W1_THERM config W1_THERM
...@@ -51,7 +51,7 @@ config W1_SMEM ...@@ -51,7 +51,7 @@ config W1_SMEM
tristate "Simple 64bit memory family implementation" tristate "Simple 64bit memory family implementation"
depends on W1 depends on W1
help help
Say Y here if you want to connect 1-wire Say Y here if you want to connect 1-wire
simple 64bit memory rom(ds2401/ds2411/ds1990*) to you wire. simple 64bit memory rom(ds2401/ds2411/ds1990*) to you wire.
endmenu endmenu
/* /*
* matrox_w1.c * matrox_w1.c
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -59,7 +59,7 @@ static struct pci_driver matrox_w1_pci_driver = { ...@@ -59,7 +59,7 @@ static struct pci_driver matrox_w1_pci_driver = {
.remove = __devexit_p(matrox_w1_remove), .remove = __devexit_p(matrox_w1_remove),
}; };
/* /*
* Matrox G400 DDC registers. * Matrox G400 DDC registers.
*/ */
...@@ -177,8 +177,8 @@ static int __devinit matrox_w1_probe(struct pci_dev *pdev, const struct pci_devi ...@@ -177,8 +177,8 @@ static int __devinit matrox_w1_probe(struct pci_dev *pdev, const struct pci_devi
dev->bus_master = (struct w1_bus_master *)(dev + 1); dev->bus_master = (struct w1_bus_master *)(dev + 1);
/* /*
* True for G400, for some other we need resource 0, see drivers/video/matrox/matroxfb_base.c * True for G400, for some other we need resource 0, see drivers/video/matrox/matroxfb_base.c
*/ */
dev->phys_addr = pci_resource_start(pdev, 1); dev->phys_addr = pci_resource_start(pdev, 1);
......
This diff is collapsed.
/* /*
* w1.h * w1.h
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
struct w1_reg_num struct w1_reg_num
{ {
#if defined(__LITTLE_ENDIAN_BITFIELD) #if defined(__LITTLE_ENDIAN_BITFIELD)
__u64 family:8, __u64 family:8,
id:48, id:48,
crc:8; crc:8;
#elif defined(__BIG_ENDIAN_BITFIELD) #elif defined(__BIG_ENDIAN_BITFIELD)
__u64 crc:8, __u64 crc:8,
id:48, id:48,
...@@ -74,11 +74,11 @@ struct w1_slave ...@@ -74,11 +74,11 @@ struct w1_slave
int ttl; int ttl;
struct w1_master *master; struct w1_master *master;
struct w1_family *family; struct w1_family *family;
struct device dev; struct device dev;
struct completion dev_released; struct completion dev_released;
struct bin_attribute attr_bin; struct bin_attribute attr_bin;
struct device_attribute attr_name, attr_val; struct device_attribute attr_name, attr_val;
}; };
...@@ -90,16 +90,16 @@ struct w1_bus_master ...@@ -90,16 +90,16 @@ struct w1_bus_master
u8 (*read_bit)(unsigned long); u8 (*read_bit)(unsigned long);
void (*write_bit)(unsigned long, u8); void (*write_bit)(unsigned long, u8);
u8 (*read_byte)(unsigned long); u8 (*read_byte)(unsigned long);
void (*write_byte)(unsigned long, u8); void (*write_byte)(unsigned long, u8);
u8 (*read_block)(unsigned long, u8 *, int); u8 (*read_block)(unsigned long, u8 *, int);
void (*write_block)(unsigned long, u8 *, int); void (*write_block)(unsigned long, u8 *, int);
u8 (*touch_bit)(unsigned long, u8); u8 (*touch_bit)(unsigned long, u8);
u8 (*reset_bus)(unsigned long); u8 (*reset_bus)(unsigned long);
void (*search)(unsigned long, w1_slave_found_callback); void (*search)(unsigned long, w1_slave_found_callback);
}; };
...@@ -123,21 +123,20 @@ struct w1_master ...@@ -123,21 +123,20 @@ struct w1_master
int need_exit; int need_exit;
pid_t kpid; pid_t kpid;
struct semaphore mutex; struct semaphore mutex;
struct device_driver *driver; struct device_driver *driver;
struct device dev; struct device dev;
struct completion dev_released; struct completion dev_released;
struct completion dev_exited; struct completion dev_exited;
struct w1_bus_master *bus_master; struct w1_bus_master *bus_master;
u32 seq, groups; u32 seq, groups;
struct sock *nls; struct sock *nls;
}; };
int w1_create_master_attributes(struct w1_master *); int w1_create_master_attributes(struct w1_master *);
void w1_destroy_master_attributes(struct w1_master *);
void w1_search(struct w1_master *dev); void w1_search(struct w1_master *dev);
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
......
/* /*
* w1_family.c * w1_family.c
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/* /*
* w1_family.h * w1_family.h
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -39,7 +39,7 @@ struct w1_family_ops ...@@ -39,7 +39,7 @@ struct w1_family_ops
{ {
ssize_t (* rname)(struct device *, struct device_attribute *, char *); ssize_t (* rname)(struct device *, struct device_attribute *, char *);
ssize_t (* rbin)(struct kobject *, char *, loff_t, size_t); ssize_t (* rbin)(struct kobject *, char *, loff_t, size_t);
ssize_t (* rval)(struct device *, struct device_attribute *, char *); ssize_t (* rval)(struct device *, struct device_attribute *, char *);
unsigned char rvalname[MAXNAMELEN]; unsigned char rvalname[MAXNAMELEN];
}; };
...@@ -48,9 +48,9 @@ struct w1_family ...@@ -48,9 +48,9 @@ struct w1_family
{ {
struct list_head family_entry; struct list_head family_entry;
u8 fid; u8 fid;
struct w1_family_ops *fops; struct w1_family_ops *fops;
atomic_t refcnt; atomic_t refcnt;
u8 need_exit; u8 need_exit;
}; };
......
/* /*
* w1_int.c * w1_int.c
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -39,8 +39,9 @@ extern spinlock_t w1_mlock; ...@@ -39,8 +39,9 @@ extern spinlock_t w1_mlock;
extern int w1_process(void *); extern int w1_process(void *);
struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
struct device_driver *driver, struct device *device) struct device_driver *driver,
struct device *device)
{ {
struct w1_master *dev; struct w1_master *dev;
int err; int err;
...@@ -60,13 +61,13 @@ struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, ...@@ -60,13 +61,13 @@ struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
dev->bus_master = (struct w1_bus_master *)(dev + 1); dev->bus_master = (struct w1_bus_master *)(dev + 1);
dev->owner = THIS_MODULE; dev->owner = THIS_MODULE;
dev->max_slave_count = slave_count; dev->max_slave_count = slave_count;
dev->slave_count = 0; dev->slave_count = 0;
dev->attempts = 0; dev->attempts = 0;
dev->kpid = -1; dev->kpid = -1;
dev->initialized = 0; dev->initialized = 0;
dev->id = id; dev->id = id;
dev->slave_ttl = slave_ttl; dev->slave_ttl = slave_ttl;
atomic_set(&dev->refcnt, 2); atomic_set(&dev->refcnt, 2);
...@@ -105,7 +106,7 @@ struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, ...@@ -105,7 +106,7 @@ struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
return dev; return dev;
} }
void w1_free_dev(struct w1_master *dev) static void w1_free_dev(struct w1_master *dev)
{ {
device_unregister(&dev->dev); device_unregister(&dev->dev);
if (dev->nls && dev->nls->sk_socket) if (dev->nls && dev->nls->sk_socket)
...@@ -197,10 +198,8 @@ void __w1_remove_master_device(struct w1_master *dev) ...@@ -197,10 +198,8 @@ void __w1_remove_master_device(struct w1_master *dev)
void w1_remove_master_device(struct w1_bus_master *bm) void w1_remove_master_device(struct w1_bus_master *bm)
{ {
struct w1_master *dev = NULL; struct w1_master *dev = NULL;
struct list_head *ent, *n;
list_for_each_safe(ent, n, &w1_masters) { list_for_each_entry(dev, &w1_masters, w1_master_entry) {
dev = list_entry(ent, struct w1_master, w1_master_entry);
if (!dev->initialized) if (!dev->initialized)
continue; continue;
......
/* /*
* w1_int.h * w1_int.h
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#include "w1.h" #include "w1.h"
struct w1_master * w1_alloc_dev(u32, int, int, struct device_driver *, struct device *);
void w1_free_dev(struct w1_master *dev);
int w1_add_master_device(struct w1_bus_master *); int w1_add_master_device(struct w1_bus_master *);
void w1_remove_master_device(struct w1_bus_master *); void w1_remove_master_device(struct w1_bus_master *);
void __w1_remove_master_device(struct w1_master *); void __w1_remove_master_device(struct w1_master *);
......
/* /*
* w1_io.c * w1_io.c
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/* /*
* w1_io.h * w1_io.h
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
/* /*
* w1_log.h * w1_log.h
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
...@@ -33,13 +33,13 @@ enum w1_netlink_message_types { ...@@ -33,13 +33,13 @@ enum w1_netlink_message_types {
W1_MASTER_REMOVE, W1_MASTER_REMOVE,
}; };
struct w1_netlink_msg struct w1_netlink_msg
{ {
__u8 type; __u8 type;
__u8 reserved[3]; __u8 reserved[3];
union union
{ {
struct w1_reg_num id; struct w1_reg_num id;
__u64 w1_id; __u64 w1_id;
struct struct
{ {
......
/* /*
* w1_smem.c * w1_smem.c
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the smems of the GNU General Public License as published by * it under the smems of the GNU General Public License as published by
...@@ -70,7 +70,7 @@ static ssize_t w1_smem_read_val(struct device *dev, struct device_attribute *att ...@@ -70,7 +70,7 @@ static ssize_t w1_smem_read_val(struct device *dev, struct device_attribute *att
static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count) static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count)
{ {
struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj), struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj),
struct w1_slave, dev); struct w1_slave, dev);
int i; int i;
atomic_inc(&sl->refcnt); atomic_inc(&sl->refcnt);
...@@ -90,7 +90,7 @@ static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, siz ...@@ -90,7 +90,7 @@ static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, siz
for (i = 0; i < 8; ++i) for (i = 0; i < 8; ++i)
count += sprintf(buf + count, "%02x ", ((u8 *)&sl->reg_num)[i]); count += sprintf(buf + count, "%02x ", ((u8 *)&sl->reg_num)[i]);
count += sprintf(buf + count, "\n"); count += sprintf(buf + count, "\n");
out: out:
up(&sl->master->mutex); up(&sl->master->mutex);
out_dec: out_dec:
......
/* /*
* w1_therm.c * w1_therm.c
* *
* Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the therms of the GNU General Public License as published by * it under the therms of the GNU General Public License as published by
...@@ -38,7 +38,7 @@ MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>"); ...@@ -38,7 +38,7 @@ MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, temperature family."); MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, temperature family.");
static u8 bad_roms[][9] = { static u8 bad_roms[][9] = {
{0xaa, 0x00, 0x4b, 0x46, 0xff, 0xff, 0x0c, 0x10, 0x87}, {0xaa, 0x00, 0x4b, 0x46, 0xff, 0xff, 0x0c, 0x10, 0x87},
{} {}
}; };
...@@ -163,7 +163,7 @@ static int w1_therm_check_rom(u8 rom[9]) ...@@ -163,7 +163,7 @@ static int w1_therm_check_rom(u8 rom[9])
static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count) static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count)
{ {
struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj), struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj),
struct w1_slave, dev); struct w1_slave, dev);
struct w1_master *dev = sl->master; struct w1_master *dev = sl->master;
u8 rom[9], crc, verdict; u8 rom[9], crc, verdict;
int i, max_trying = 10; int i, max_trying = 10;
...@@ -198,7 +198,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si ...@@ -198,7 +198,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
unsigned int tm = 750; unsigned int tm = 750;
memcpy(&match[1], (u64 *) & sl->reg_num, 8); memcpy(&match[1], (u64 *) & sl->reg_num, 8);
w1_write_block(dev, match, 9); w1_write_block(dev, match, 9);
w1_write_8(dev, W1_CONVERT_TEMP); w1_write_8(dev, W1_CONVERT_TEMP);
...@@ -211,7 +211,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si ...@@ -211,7 +211,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
if (!w1_reset_bus (dev)) { if (!w1_reset_bus (dev)) {
w1_write_block(dev, match, 9); w1_write_block(dev, match, 9);
w1_write_8(dev, W1_READ_SCRATCHPAD); w1_write_8(dev, W1_READ_SCRATCHPAD);
if ((count = w1_read_block(dev, rom, 9)) != 9) { if ((count = w1_read_block(dev, rom, 9)) != 9) {
dev_warn(&dev->dev, "w1_read_block() returned %d instead of 9.\n", count); dev_warn(&dev->dev, "w1_read_block() returned %d instead of 9.\n", count);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment