Skip to content

Commit c4019b7

Browse files
Wolfram SangWolfram Sang
authored andcommitted
i2c: make address check indpendent from client struct
We want to use this function with struct boardinfo soon, so let's just pass the parameters really needed. We also extend the type of addr, so more types can be input. Remove a superfluous dangling comment while here. Tested-by: Andrey Danin <danindrey@mail.ru> Acked-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
1 parent 66be605 commit c4019b7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/i2c/i2c-core.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -798,15 +798,15 @@ static unsigned short i2c_encode_flags_to_addr(struct i2c_client *client)
798798

799799
/* This is a permissive address validity check, I2C address map constraints
800800
* are purposely not enforced, except for the general call address. */
801-
static int i2c_check_addr_validity(const struct i2c_client *client)
801+
static int i2c_check_addr_validity(unsigned addr, unsigned short flags)
802802
{
803-
if (client->flags & I2C_CLIENT_TEN) {
803+
if (flags & I2C_CLIENT_TEN) {
804804
/* 10-bit address, all values are valid */
805-
if (client->addr > 0x3ff)
805+
if (addr > 0x3ff)
806806
return -EINVAL;
807807
} else {
808808
/* 7-bit address, reject the general call address */
809-
if (client->addr == 0x00 || client->addr > 0x7f)
809+
if (addr == 0x00 || addr > 0x7f)
810810
return -EINVAL;
811811
}
812812
return 0;
@@ -984,8 +984,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
984984

985985
strlcpy(client->name, info->type, sizeof(client->name));
986986

987-
/* Check for address validity */
988-
status = i2c_check_addr_validity(client);
987+
status = i2c_check_addr_validity(client->addr, client->flags);
989988
if (status) {
990989
dev_err(&adap->dev, "Invalid %d-bit I2C address 0x%02hx\n",
991990
client->flags & I2C_CLIENT_TEN ? 10 : 7, client->addr);

0 commit comments

Comments
 (0)