Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
7481987d
Commit
7481987d
authored
Apr 09, 2003
by
Greg Kroah-Hartman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
i2c: clean up i2c-dev.c's formatting, DEBUG, and ioctl mess
parent
8f84a3f1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
57 deletions
+52
-57
drivers/i2c/i2c-dev.c
drivers/i2c/i2c-dev.c
+46
-51
include/linux/i2c-dev.h
include/linux/i2c-dev.h
+3
-3
include/linux/i2c.h
include/linux/i2c.h
+3
-3
No files found.
drivers/i2c/i2c-dev.c
View file @
7481987d
...
@@ -77,7 +77,7 @@ static struct i2c_adapter *i2cdev_adaps[I2CDEV_ADAPS_MAX];
...
@@ -77,7 +77,7 @@ static struct i2c_adapter *i2cdev_adaps[I2CDEV_ADAPS_MAX];
static
struct
i2c_driver
i2cdev_driver
=
{
static
struct
i2c_driver
i2cdev_driver
=
{
.
owner
=
THIS_MODULE
,
.
owner
=
THIS_MODULE
,
.
name
=
"
i2c-dev dummy
driver"
,
.
name
=
"
dev
driver"
,
.
id
=
I2C_DRIVERID_I2CDEV
,
.
id
=
I2C_DRIVERID_I2CDEV
,
.
flags
=
I2C_DF_DUMMY
,
.
flags
=
I2C_DF_DUMMY
,
.
attach_adapter
=
i2cdev_attach_adapter
,
.
attach_adapter
=
i2cdev_attach_adapter
,
...
@@ -100,10 +100,6 @@ static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
...
@@ -100,10 +100,6 @@ static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
char
*
tmp
;
char
*
tmp
;
int
ret
;
int
ret
;
#ifdef DEBUG
struct
inode
*
inode
=
file
->
f_dentry
->
d_inode
;
#endif
/* DEBUG */
struct
i2c_client
*
client
=
(
struct
i2c_client
*
)
file
->
private_data
;
struct
i2c_client
*
client
=
(
struct
i2c_client
*
)
file
->
private_data
;
if
(
count
>
8192
)
if
(
count
>
8192
)
...
@@ -114,10 +110,8 @@ static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
...
@@ -114,10 +110,8 @@ static ssize_t i2cdev_read (struct file *file, char *buf, size_t count,
if
(
tmp
==
NULL
)
if
(
tmp
==
NULL
)
return
-
ENOMEM
;
return
-
ENOMEM
;
#ifdef DEBUG
pr_debug
(
"i2c-dev.o: i2c-%d reading %d bytes.
\n
"
,
printk
(
KERN_DEBUG
"i2c-dev.o: i2c-%d reading %d bytes.
\n
"
,
minor
(
inode
->
i_rdev
),
minor
(
file
->
f_dentry
->
d_inode
->
i_rdev
),
count
);
count
);
#endif
ret
=
i2c_master_recv
(
client
,
tmp
,
count
);
ret
=
i2c_master_recv
(
client
,
tmp
,
count
);
if
(
ret
>=
0
)
if
(
ret
>=
0
)
...
@@ -133,10 +127,6 @@ static ssize_t i2cdev_write (struct file *file, const char *buf, size_t count,
...
@@ -133,10 +127,6 @@ static ssize_t i2cdev_write (struct file *file, const char *buf, size_t count,
char
*
tmp
;
char
*
tmp
;
struct
i2c_client
*
client
=
(
struct
i2c_client
*
)
file
->
private_data
;
struct
i2c_client
*
client
=
(
struct
i2c_client
*
)
file
->
private_data
;
#ifdef DEBUG
struct
inode
*
inode
=
file
->
f_dentry
->
d_inode
;
#endif
/* DEBUG */
if
(
count
>
8192
)
if
(
count
>
8192
)
count
=
8192
;
count
=
8192
;
...
@@ -149,10 +139,9 @@ static ssize_t i2cdev_write (struct file *file, const char *buf, size_t count,
...
@@ -149,10 +139,9 @@ static ssize_t i2cdev_write (struct file *file, const char *buf, size_t count,
return
-
EFAULT
;
return
-
EFAULT
;
}
}
#ifdef DEBUG
pr_debug
(
"i2c-dev.o: i2c-%d writing %d bytes.
\n
"
,
printk
(
KERN_DEBUG
"i2c-dev.o: i2c-%d writing %d bytes.
\n
"
,
minor
(
inode
->
i_rdev
),
minor
(
file
->
f_dentry
->
d_inode
->
i_rdev
),
count
);
count
);
#endif
ret
=
i2c_master_send
(
client
,
tmp
,
count
);
ret
=
i2c_master_send
(
client
,
tmp
,
count
);
kfree
(
tmp
);
kfree
(
tmp
);
return
ret
;
return
ret
;
...
@@ -169,10 +158,8 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
...
@@ -169,10 +158,8 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
int
i
,
datasize
,
res
;
int
i
,
datasize
,
res
;
unsigned
long
funcs
;
unsigned
long
funcs
;
#ifdef DEBUG
pr_debug
(
"i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.
\n
"
,
printk
(
KERN_DEBUG
"i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.
\n
"
,
minor
(
inode
->
i_rdev
),
cmd
,
arg
);
minor
(
inode
->
i_rdev
),
cmd
,
arg
);
#endif
/* DEBUG */
switch
(
cmd
)
{
switch
(
cmd
)
{
case
I2C_SLAVE
:
case
I2C_SLAVE
:
...
@@ -207,6 +194,11 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
...
@@ -207,6 +194,11 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
sizeof
(
rdwr_arg
)))
sizeof
(
rdwr_arg
)))
return
-
EFAULT
;
return
-
EFAULT
;
/* Put an arbritrary limit on the number of messages that can
* be sent at once */
if
(
rdwr_arg
.
nmsgs
>
42
)
return
-
EINVAL
;
rdwr_pa
=
(
struct
i2c_msg
*
)
rdwr_pa
=
(
struct
i2c_msg
*
)
kmalloc
(
rdwr_arg
.
nmsgs
*
sizeof
(
struct
i2c_msg
),
kmalloc
(
rdwr_arg
.
nmsgs
*
sizeof
(
struct
i2c_msg
),
GFP_KERNEL
);
GFP_KERNEL
);
...
@@ -214,38 +206,43 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
...
@@ -214,38 +206,43 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
if
(
rdwr_pa
==
NULL
)
return
-
ENOMEM
;
if
(
rdwr_pa
==
NULL
)
return
-
ENOMEM
;
res
=
0
;
res
=
0
;
for
(
i
=
0
;
i
<
rdwr_arg
.
nmsgs
;
i
++
)
for
(
i
=
0
;
i
<
rdwr_arg
.
nmsgs
;
i
++
)
{
{
if
(
copy_from_user
(
&
(
rdwr_pa
[
i
]),
if
(
copy_from_user
(
&
(
rdwr_pa
[
i
]),
&
(
rdwr_arg
.
msgs
[
i
]),
&
(
rdwr_arg
.
msgs
[
i
]),
sizeof
(
rdwr_pa
[
i
])))
sizeof
(
rdwr_pa
[
i
])))
{
{
res
=
-
EFAULT
;
res
=
-
EFAULT
;
break
;
break
;
}
}
/* Limit the size of the message to a sane amount */
if
(
rdwr_pa
[
i
].
len
>
8192
)
{
res
=
-
EINVAL
;
break
;
}
rdwr_pa
[
i
].
buf
=
kmalloc
(
rdwr_pa
[
i
].
len
,
GFP_KERNEL
);
rdwr_pa
[
i
].
buf
=
kmalloc
(
rdwr_pa
[
i
].
len
,
GFP_KERNEL
);
if
(
rdwr_pa
[
i
].
buf
==
NULL
)
if
(
rdwr_pa
[
i
].
buf
==
NULL
)
{
{
res
=
-
ENOMEM
;
res
=
-
ENOMEM
;
break
;
break
;
}
}
if
(
copy_from_user
(
rdwr_pa
[
i
].
buf
,
if
(
copy_from_user
(
rdwr_pa
[
i
].
buf
,
rdwr_arg
.
msgs
[
i
].
buf
,
rdwr_arg
.
msgs
[
i
].
buf
,
rdwr_pa
[
i
].
len
))
rdwr_pa
[
i
].
len
))
{
{
kfree
(
rdwr_pa
[
i
].
buf
);
res
=
-
EFAULT
;
res
=
-
EFAULT
;
break
;
break
;
}
}
}
}
if
(
!
res
)
if
(
res
<
0
)
{
{
int
j
;
for
(
j
=
0
;
j
<
i
;
++
j
)
kfree
(
rdwr_pa
[
j
].
buf
);
kfree
(
rdwr_pa
);
return
res
;
}
if
(
!
res
)
{
res
=
i2c_transfer
(
client
->
adapter
,
res
=
i2c_transfer
(
client
->
adapter
,
rdwr_pa
,
rdwr_pa
,
rdwr_arg
.
nmsgs
);
rdwr_arg
.
nmsgs
);
}
}
while
(
i
--
>
0
)
while
(
i
--
>
0
)
{
{
if
(
res
>=
0
&&
(
rdwr_pa
[
i
].
flags
&
I2C_M_RD
))
if
(
res
>=
0
&&
(
rdwr_pa
[
i
].
flags
&
I2C_M_RD
))
{
{
if
(
copy_to_user
(
if
(
copy_to_user
(
...
@@ -274,20 +271,18 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
...
@@ -274,20 +271,18 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
(
data_arg
.
size
!=
I2C_SMBUS_BLOCK_DATA
)
&&
(
data_arg
.
size
!=
I2C_SMBUS_BLOCK_DATA
)
&&
(
data_arg
.
size
!=
I2C_SMBUS_I2C_BLOCK_DATA
)
&&
(
data_arg
.
size
!=
I2C_SMBUS_I2C_BLOCK_DATA
)
&&
(
data_arg
.
size
!=
I2C_SMBUS_BLOCK_PROC_CALL
))
{
(
data_arg
.
size
!=
I2C_SMBUS_BLOCK_PROC_CALL
))
{
#ifdef DEBUG
dev_dbg
(
&
client
->
dev
,
printk
(
KERN_DEBUG
"i2c-dev.o:
size out of range (%x) in ioctl I2C_SMBUS.
\n
"
,
"
size out of range (%x) in ioctl I2C_SMBUS.
\n
"
,
data_arg
.
size
);
data_arg
.
size
);
#endif
return
-
EINVAL
;
return
-
EINVAL
;
}
}
/* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1,
/* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1,
so the check is valid if size==I2C_SMBUS_QUICK too. */
so the check is valid if size==I2C_SMBUS_QUICK too. */
if
((
data_arg
.
read_write
!=
I2C_SMBUS_READ
)
&&
if
((
data_arg
.
read_write
!=
I2C_SMBUS_READ
)
&&
(
data_arg
.
read_write
!=
I2C_SMBUS_WRITE
))
{
(
data_arg
.
read_write
!=
I2C_SMBUS_WRITE
))
{
#ifdef DEBUG
dev_dbg
(
&
client
->
dev
,
printk
(
KERN_DEBUG
"i2c-dev.o:
read_write out of range (%x) in ioctl I2C_SMBUS.
\n
"
,
"
read_write out of range (%x) in ioctl I2C_SMBUS.
\n
"
,
data_arg
.
read_write
);
data_arg
.
read_write
);
#endif
return
-
EINVAL
;
return
-
EINVAL
;
}
}
...
@@ -304,9 +299,8 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
...
@@ -304,9 +299,8 @@ int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
data_arg
.
size
,
NULL
);
data_arg
.
size
,
NULL
);
if
(
data_arg
.
data
==
NULL
)
{
if
(
data_arg
.
data
==
NULL
)
{
#ifdef DEBUG
dev_dbg
(
&
client
->
dev
,
printk
(
KERN_DEBUG
"i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.
\n
"
);
"data is NULL pointer in ioctl I2C_SMBUS.
\n
"
);
#endif
return
-
EINVAL
;
return
-
EINVAL
;
}
}
...
@@ -365,7 +359,7 @@ static int i2cdev_open(struct inode *inode, struct file *file)
...
@@ -365,7 +359,7 @@ static int i2cdev_open(struct inode *inode, struct file *file)
return
0
;
return
0
;
out_kfree:
out_kfree:
kfree
(
client
);
kfree
(
client
);
return
-
ENODEV
;
return
-
ENODEV
;
}
}
...
@@ -428,7 +422,8 @@ int __init i2c_dev_init(void)
...
@@ -428,7 +422,8 @@ int __init i2c_dev_init(void)
{
{
int
res
;
int
res
;
printk
(
KERN_INFO
"i2c-dev.o: i2c /dev entries driver module version %s (%s)
\n
"
,
I2C_VERSION
,
I2C_DATE
);
printk
(
KERN_INFO
"i2c /dev entries driver module version %s (%s)
\n
"
,
I2C_VERSION
,
I2C_DATE
);
if
(
register_chrdev
(
I2C_MAJOR
,
"i2c"
,
&
i2cdev_fops
))
{
if
(
register_chrdev
(
I2C_MAJOR
,
"i2c"
,
&
i2cdev_fops
))
{
printk
(
KERN_ERR
"i2c-dev.o: unable to get major %d for i2c bus
\n
"
,
printk
(
KERN_ERR
"i2c-dev.o: unable to get major %d for i2c bus
\n
"
,
...
...
include/linux/i2c-dev.h
View file @
7481987d
...
@@ -31,16 +31,16 @@
...
@@ -31,16 +31,16 @@
/* This is the structure as used in the I2C_SMBUS ioctl call */
/* This is the structure as used in the I2C_SMBUS ioctl call */
struct
i2c_smbus_ioctl_data
{
struct
i2c_smbus_ioctl_data
{
char
read_write
;
__u8
read_write
;
__u8
command
;
__u8
command
;
int
size
;
__u32
size
;
union
i2c_smbus_data
*
data
;
union
i2c_smbus_data
*
data
;
};
};
/* This is the structure as used in the I2C_RDWR ioctl call */
/* This is the structure as used in the I2C_RDWR ioctl call */
struct
i2c_rdwr_ioctl_data
{
struct
i2c_rdwr_ioctl_data
{
struct
i2c_msg
*
msgs
;
/* pointers to i2c_msgs */
struct
i2c_msg
*
msgs
;
/* pointers to i2c_msgs */
int
nmsgs
;
/* number of i2c_msgs */
__u32
nmsgs
;
/* number of i2c_msgs */
};
};
#endif
/* _LINUX_I2C_DEV_H */
#endif
/* _LINUX_I2C_DEV_H */
include/linux/i2c.h
View file @
7481987d
...
@@ -367,15 +367,15 @@ extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
...
@@ -367,15 +367,15 @@ extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func);
*/
*/
struct
i2c_msg
{
struct
i2c_msg
{
__u16
addr
;
/* slave address */
__u16
addr
;
/* slave address */
unsigned
short
flags
;
__u16
flags
;
#define I2C_M_TEN 0x10
/* we have a ten bit chip address */
#define I2C_M_TEN 0x10
/* we have a ten bit chip address */
#define I2C_M_RD 0x01
#define I2C_M_RD 0x01
#define I2C_M_NOSTART 0x4000
#define I2C_M_NOSTART 0x4000
#define I2C_M_REV_DIR_ADDR 0x2000
#define I2C_M_REV_DIR_ADDR 0x2000
#define I2C_M_IGNORE_NAK 0x1000
#define I2C_M_IGNORE_NAK 0x1000
#define I2C_M_NO_RD_ACK 0x0800
#define I2C_M_NO_RD_ACK 0x0800
short
len
;
/* msg length */
__u16
len
;
/* msg length */
char
*
buf
;
/* pointer to msg data */
__u8
*
buf
;
/* pointer to msg data */
};
};
/* To determine what functionality is present */
/* To determine what functionality is present */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment