Polish source to WARNS=6
This commit is contained in:
parent
ed93deba11
commit
9db7da1f55
@ -3,6 +3,6 @@
|
|||||||
PROG= i2c
|
PROG= i2c
|
||||||
MAN= i2c.8
|
MAN= i2c.8
|
||||||
|
|
||||||
WARNS?= 2
|
WARNS?= 6
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
@ -36,7 +37,6 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
@ -122,12 +122,13 @@ skip_get_tokens(char *skip_addr, int *sk_addr, int max_index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
scan_bus(struct iiccmd cmd, char *dev, int skip, char *skip_addr)
|
scan_bus(const char *dev, int skip, char *skip_addr)
|
||||||
{
|
{
|
||||||
|
struct iiccmd cmd;
|
||||||
struct iic_msg rdmsg;
|
struct iic_msg rdmsg;
|
||||||
struct iic_rdwr_data rdwrdata;
|
struct iic_rdwr_data rdwrdata;
|
||||||
struct skip_range addr_range = { 0, 0 };
|
struct skip_range addr_range = { 0, 0 };
|
||||||
int *tokens, fd, error, i, index, j;
|
int *tokens = NULL, fd, error, i, idx = 0, j;
|
||||||
int len = 0, do_skip = 0, no_range = 1, num_found = 0, use_read_xfer = 0;
|
int len = 0, do_skip = 0, no_range = 1, num_found = 0, use_read_xfer = 0;
|
||||||
uint8_t rdbyte;
|
uint8_t rdbyte;
|
||||||
|
|
||||||
@ -139,6 +140,7 @@ scan_bus(struct iiccmd cmd, char *dev, int skip, char *skip_addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (skip) {
|
if (skip) {
|
||||||
|
assert(skip_addr != NULL);
|
||||||
len = strlen(skip_addr);
|
len = strlen(skip_addr);
|
||||||
if (strstr(skip_addr, "..") != NULL) {
|
if (strstr(skip_addr, "..") != NULL) {
|
||||||
addr_range = skip_get_range(skip_addr);
|
addr_range = skip_get_range(skip_addr);
|
||||||
@ -151,7 +153,7 @@ scan_bus(struct iiccmd cmd, char *dev, int skip, char *skip_addr)
|
|||||||
error = -1;
|
error = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
index = skip_get_tokens(skip_addr, tokens,
|
idx = skip_get_tokens(skip_addr, tokens,
|
||||||
len / 2 + 1);
|
len / 2 + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,13 +179,15 @@ scan_bus(struct iiccmd cmd, char *dev, int skip, char *skip_addr)
|
|||||||
if (i >= addr_range.start && i <= addr_range.end)
|
if (i >= addr_range.start && i <= addr_range.end)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
} else if (skip && no_range)
|
} else if (skip && no_range) {
|
||||||
for (j = 0; j < index; j++) {
|
assert (tokens != NULL);
|
||||||
|
for (j = 0; j < idx; j++) {
|
||||||
if (tokens[j] == i) {
|
if (tokens[j] == i) {
|
||||||
do_skip = 1;
|
do_skip = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (do_skip) {
|
if (do_skip) {
|
||||||
do_skip = 0;
|
do_skip = 0;
|
||||||
@ -241,6 +245,8 @@ scan_bus(struct iiccmd cmd, char *dev, int skip, char *skip_addr)
|
|||||||
close(fd);
|
close(fd);
|
||||||
if (skip && no_range)
|
if (skip && no_range)
|
||||||
free(tokens);
|
free(tokens);
|
||||||
|
else
|
||||||
|
assert(tokens == NULL);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
fprintf(stderr, "Error scanning I2C controller (%s): %s\n",
|
fprintf(stderr, "Error scanning I2C controller (%s): %s\n",
|
||||||
@ -251,8 +257,9 @@ scan_bus(struct iiccmd cmd, char *dev, int skip, char *skip_addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
reset_bus(struct iiccmd cmd, char *dev)
|
reset_bus(const char *dev)
|
||||||
{
|
{
|
||||||
|
struct iiccmd cmd;
|
||||||
int fd, error;
|
int fd, error;
|
||||||
|
|
||||||
fd = open(dev, O_RDWR);
|
fd = open(dev, O_RDWR);
|
||||||
@ -295,11 +302,12 @@ prepare_buf(int size, uint32_t off)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
i2c_write(char *dev, struct options i2c_opt, char *i2c_buf)
|
i2c_write(const char *dev, struct options i2c_opt, char *i2c_buf)
|
||||||
{
|
{
|
||||||
struct iiccmd cmd;
|
struct iiccmd cmd;
|
||||||
int error, fd, bufsize;
|
int error, fd, bufsize;
|
||||||
char *err_msg, *buf;
|
char *buf;
|
||||||
|
const char *err_msg;
|
||||||
|
|
||||||
fd = open(dev, O_RDWR);
|
fd = open(dev, O_RDWR);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
@ -448,11 +456,12 @@ i2c_write(char *dev, struct options i2c_opt, char *i2c_buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
i2c_read(char *dev, struct options i2c_opt, char *i2c_buf)
|
i2c_read(const char *dev, struct options i2c_opt, char *i2c_buf)
|
||||||
{
|
{
|
||||||
struct iiccmd cmd;
|
struct iiccmd cmd;
|
||||||
int fd, error, bufsize;
|
int fd, error, bufsize;
|
||||||
char *err_msg, data = 0, *buf;
|
char data = 0, *buf;
|
||||||
|
const char *err_msg;
|
||||||
|
|
||||||
fd = open(dev, O_RDWR);
|
fd = open(dev, O_RDWR);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
@ -556,7 +565,7 @@ i2c_read(char *dev, struct options i2c_opt, char *i2c_buf)
|
|||||||
* driver to be handled as a single transfer.
|
* driver to be handled as a single transfer.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
i2c_rdwr_transfer(char *dev, struct options i2c_opt, char *i2c_buf)
|
i2c_rdwr_transfer(const char *dev, struct options i2c_opt, char *i2c_buf)
|
||||||
{
|
{
|
||||||
struct iic_msg msgs[2];
|
struct iic_msg msgs[2];
|
||||||
struct iic_rdwr_data xfer;
|
struct iic_rdwr_data xfer;
|
||||||
@ -613,9 +622,9 @@ i2c_rdwr_transfer(char *dev, struct options i2c_opt, char *i2c_buf)
|
|||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
struct iiccmd cmd;
|
|
||||||
struct options i2c_opt;
|
struct options i2c_opt;
|
||||||
char *dev, *skip_addr, *i2c_buf;
|
char *skip_addr = NULL, *i2c_buf;
|
||||||
|
const char *dev;
|
||||||
int error, chunk_size, i, j, ch;
|
int error, chunk_size, i, j, ch;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@ -700,6 +709,10 @@ main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
if (argc > 0) {
|
||||||
|
fprintf(stderr, "Too many arguments\n");
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
|
||||||
/* Set default mode if option -m is not specified */
|
/* Set default mode if option -m is not specified */
|
||||||
if (i2c_opt.mode == I2C_MODE_NOTSET) {
|
if (i2c_opt.mode == I2C_MODE_NOTSET) {
|
||||||
@ -727,15 +740,15 @@ main(int argc, char** argv)
|
|||||||
|
|
||||||
if (i2c_opt.verbose)
|
if (i2c_opt.verbose)
|
||||||
fprintf(stderr, "dev: %s, addr: 0x%x, r/w: %c, "
|
fprintf(stderr, "dev: %s, addr: 0x%x, r/w: %c, "
|
||||||
"offset: 0x%02x, width: %u, count: %u\n", dev,
|
"offset: 0x%02x, width: %d, count: %d\n", dev,
|
||||||
i2c_opt.addr >> 1, i2c_opt.dir, i2c_opt.off,
|
i2c_opt.addr >> 1, i2c_opt.dir, i2c_opt.off,
|
||||||
i2c_opt.width, i2c_opt.count);
|
i2c_opt.width, i2c_opt.count);
|
||||||
|
|
||||||
if (i2c_opt.scan)
|
if (i2c_opt.scan)
|
||||||
exit(scan_bus(cmd, dev, i2c_opt.skip, skip_addr));
|
exit(scan_bus(dev, i2c_opt.skip, skip_addr));
|
||||||
|
|
||||||
if (i2c_opt.reset)
|
if (i2c_opt.reset)
|
||||||
exit(reset_bus(cmd, dev));
|
exit(reset_bus(dev));
|
||||||
|
|
||||||
i2c_buf = malloc(i2c_opt.count);
|
i2c_buf = malloc(i2c_opt.count);
|
||||||
if (i2c_buf == NULL)
|
if (i2c_buf == NULL)
|
||||||
@ -746,7 +759,7 @@ main(int argc, char** argv)
|
|||||||
*/
|
*/
|
||||||
if (i2c_opt.dir == 'w') {
|
if (i2c_opt.dir == 'w') {
|
||||||
if (i2c_opt.verbose && !i2c_opt.binary)
|
if (i2c_opt.verbose && !i2c_opt.binary)
|
||||||
fprintf(stderr, "Enter %u bytes of data: ",
|
fprintf(stderr, "Enter %d bytes of data: ",
|
||||||
i2c_opt.count);
|
i2c_opt.count);
|
||||||
for (i = 0; i < i2c_opt.count; i++) {
|
for (i = 0; i < i2c_opt.count; i++) {
|
||||||
ch = getchar();
|
ch = getchar();
|
||||||
|
Loading…
Reference in New Issue
Block a user