Skip to content

Commit c7dc59f

Browse files
jilaypandyakartben
authored andcommitted
drivers: ethernet phy_dm8806_read_reg reduce nested-ifs
reduce if nesting a bit using early break Signed-off-by: Jilay Pandya <[email protected]>
1 parent 9992eb9 commit c7dc59f

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

drivers/ethernet/phy/phy_dm8806.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int phy_dm8806_write_reg(const struct device *dev, uint8_t phyad, uint8_t
146146
repetition);
147147
if (repetition >= CONFIG_PHY_DM8806_SMI_BUS_CHECK_REPETITION) {
148148
LOG_ERR("Maximum number of PHY write repetition exceed.");
149-
res = (-EIO);
149+
res = -EIO;
150150
}
151151
} else {
152152
break;
@@ -158,7 +158,7 @@ static int phy_dm8806_write_reg(const struct device *dev, uint8_t phyad, uint8_t
158158
} else {
159159
if (checksum_mismatch) {
160160
LOG_ERR("Wrong checksum, during PHY write procedure.");
161-
res = (-EIO);
161+
res = -EIO;
162162
break;
163163
}
164164
}
@@ -217,20 +217,18 @@ static int phy_dm8806_read_reg(const struct device *dev, uint8_t phyad, uint8_t
217217

218218
if (CONFIG_PHY_DM8806_SMI_BUS_CHECK_REPETITION > 0) {
219219
repetition++;
220-
if (hw_checksum != sw_checksum) {
221-
LOG_WRN("%d repeat of PHY read procedure due to checksum error.",
222-
repetition);
223-
if (repetition >= CONFIG_PHY_DM8806_SMI_BUS_CHECK_REPETITION) {
224-
LOG_ERR("Maximum number of PHY read repetition exceed.");
225-
res = (-EIO);
226-
}
227-
} else {
220+
if (hw_checksum == sw_checksum) {
228221
break;
229222
}
223+
LOG_WRN("%d repeat PHY read procedure due to checksum error.", repetition);
224+
if (repetition >= CONFIG_PHY_DM8806_SMI_BUS_CHECK_REPETITION) {
225+
LOG_ERR("Maximum number of PHY read repetition exceed.");
226+
res = -EIO;
227+
}
230228
} else {
231229
if (hw_checksum != sw_checksum) {
232230
LOG_ERR("Wrong checksum, during PHY read procedure.");
233-
res = (-EIO);
231+
res = -EIO;
234232
break;
235233
}
236234
}
@@ -335,14 +333,14 @@ int phy_dm8806_init_interrupt(const struct device *dev)
335333
*/
336334
res = mdio_read(cfg->mdio, DM8806_INT_MASK_CTRL_PHY_ADDR, DM8806_INT_MASK_CTRL_REG_ADDR,
337335
&data);
338-
if (res) {
336+
if (res < 0) {
339337
LOG_ERR("Failed to read IRQ_LED_CONTROL, %i", res);
340338
return res;
341339
}
342340
data |= 0x1;
343341
res = mdio_write(cfg->mdio, DM8806_INT_MASK_CTRL_PHY_ADDR, DM8806_INT_MASK_CTRL_REG_ADDR,
344342
data);
345-
if (res) {
343+
if (res < 0) {
346344
LOG_ERR("Failed to read IRQ_LED_CONTROL, %i", res);
347345
return res;
348346
}
@@ -352,14 +350,14 @@ int phy_dm8806_init_interrupt(const struct device *dev)
352350
*/
353351
res = mdio_read(cfg->mdio, DM8806_WOLL_CTRL_REG_PHY_ADDR, DM8806_WOLL_CTRL_REG_REG_ADDR,
354352
&data);
355-
if (res) {
353+
if (res < 0) {
356354
LOG_ERR("Failed to read IRQ_LED_CONTROL, %i", res);
357355
return res;
358356
}
359357
data |= 0xF;
360358
res = mdio_write(cfg->mdio, DM8806_WOLL_CTRL_REG_PHY_ADDR, DM8806_WOLL_CTRL_REG_REG_ADDR,
361359
data);
362-
if (res) {
360+
if (res < 0) {
363361
LOG_ERR("Failed to read IRQ_LED_CONTROL, %i", res);
364362
return res;
365363
}
@@ -634,7 +632,7 @@ static int phy_dm8806_reg_read(const struct device *dev, uint16_t reg_addr, uint
634632
const struct phy_dm8806_config *cfg = dev->config;
635633

636634
res = mdio_read(cfg->mdio, cfg->switch_addr, reg_addr, (uint16_t *)data);
637-
if (res) {
635+
if (res < 0) {
638636
LOG_ERR("Failed to read data from DM8806");
639637
return res;
640638
}
@@ -647,7 +645,7 @@ static int phy_dm8806_reg_write(const struct device *dev, uint16_t reg_addr, uin
647645
const struct phy_dm8806_config *cfg = dev->config;
648646

649647
res = mdio_write(cfg->mdio, cfg->switch_addr, reg_addr, data);
650-
if (res) {
648+
if (res < 0) {
651649
LOG_ERR("Failed to write data to DM8806");
652650
return res;
653651
}

0 commit comments

Comments
 (0)