Skip to content

Commit 1736736

Browse files
maass-hamburgkartben
authored andcommitted
drivers: ethernet: stm32: remove asserts and move var initialization
remove unneded asserts and move variables initialization Signed-off-by: Fin Maaß <[email protected]>
1 parent 745d762 commit 1736736

File tree

1 file changed

+26
-82
lines changed

1 file changed

+26
-82
lines changed

drivers/ethernet/eth_stm32_hal.c

Lines changed: 26 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void HAL_ETH_TxPtpCallback(uint32_t *buff, ETH_TimeStampTypeDef *timestamp)
326326
static int eth_tx(const struct device *dev, struct net_pkt *pkt)
327327
{
328328
struct eth_stm32_hal_dev_data *dev_data = dev->data;
329-
ETH_HandleTypeDef *heth;
329+
ETH_HandleTypeDef *heth = &dev_data->heth;
330330
int res;
331331
size_t total_len;
332332
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
@@ -344,10 +344,6 @@ static int eth_tx(const struct device *dev, struct net_pkt *pkt)
344344

345345
__ASSERT_NO_MSG(pkt != NULL);
346346
__ASSERT_NO_MSG(pkt->frags != NULL);
347-
__ASSERT_NO_MSG(dev != NULL);
348-
__ASSERT_NO_MSG(dev_data != NULL);
349-
350-
heth = &dev_data->heth;
351347

352348
total_len = net_pkt_get_len(pkt);
353349
if (total_len > (ETH_STM32_TX_BUF_SIZE * ETH_TXBUFNB)) {
@@ -518,8 +514,8 @@ static struct net_if *get_iface(struct eth_stm32_hal_dev_data *ctx)
518514

519515
static struct net_pkt *eth_rx(const struct device *dev)
520516
{
521-
struct eth_stm32_hal_dev_data *dev_data;
522-
ETH_HandleTypeDef *heth;
517+
struct eth_stm32_hal_dev_data *dev_data = dev->data;
518+
ETH_HandleTypeDef *heth = &dev_data->heth;
523519
struct net_pkt *pkt;
524520
size_t total_len = 0;
525521
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
@@ -538,14 +534,6 @@ static struct net_pkt *eth_rx(const struct device *dev)
538534
timestamp.nanosecond = UINT32_MAX;
539535
#endif /* CONFIG_PTP_CLOCK_STM32_HAL */
540536

541-
__ASSERT_NO_MSG(dev != NULL);
542-
543-
dev_data = dev->data;
544-
545-
__ASSERT_NO_MSG(dev_data != NULL);
546-
547-
heth = &dev_data->heth;
548-
549537
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
550538
if (HAL_ETH_ReadData(heth, &appbuf) != HAL_OK) {
551539
/* no frame available */
@@ -657,21 +645,15 @@ static struct net_pkt *eth_rx(const struct device *dev)
657645

658646
static void rx_thread(void *arg1, void *unused1, void *unused2)
659647
{
660-
const struct device *dev;
661-
struct eth_stm32_hal_dev_data *dev_data;
648+
const struct device *dev = (const struct device *)arg1;
649+
struct eth_stm32_hal_dev_data *dev_data = dev->data;
662650
struct net_if *iface;
663651
struct net_pkt *pkt;
664652
int res;
665653

666-
__ASSERT_NO_MSG(arg1 != NULL);
667654
ARG_UNUSED(unused1);
668655
ARG_UNUSED(unused2);
669656

670-
dev = (const struct device *)arg1;
671-
dev_data = dev->data;
672-
673-
__ASSERT_NO_MSG(dev_data != NULL);
674-
675657
while (1) {
676658
res = k_sem_take(&dev_data->rx_int_sem, K_FOREVER);
677659
if (res == 0) {
@@ -696,18 +678,8 @@ static void rx_thread(void *arg1, void *unused1, void *unused2)
696678

697679
static void eth_isr(const struct device *dev)
698680
{
699-
struct eth_stm32_hal_dev_data *dev_data;
700-
ETH_HandleTypeDef *heth;
701-
702-
__ASSERT_NO_MSG(dev != NULL);
703-
704-
dev_data = dev->data;
705-
706-
__ASSERT_NO_MSG(dev_data != NULL);
707-
708-
heth = &dev_data->heth;
709-
710-
__ASSERT_NO_MSG(heth != NULL);
681+
struct eth_stm32_hal_dev_data *dev_data = dev->data;
682+
ETH_HandleTypeDef *heth = &dev_data->heth;
711683

712684
HAL_ETH_IRQHandler(heth);
713685
}
@@ -966,13 +938,11 @@ static int eth_initialize(const struct device *dev)
966938
static void eth_stm32_mcast_filter(const struct device *dev, const struct ethernet_filter *filter)
967939
{
968940
struct eth_stm32_hal_dev_data *dev_data = (struct eth_stm32_hal_dev_data *)dev->data;
969-
ETH_HandleTypeDef *heth;
941+
ETH_HandleTypeDef *heth = &dev_data->heth;
970942
uint32_t crc;
971943
uint32_t hash_table[2];
972944
uint32_t hash_index;
973945

974-
heth = &dev_data->heth;
975-
976946
crc = __RBIT(crc32_ieee(filter->mac_address.addr, sizeof(struct net_eth_addr)));
977947
hash_index = (crc >> 26) & 0x3f;
978948

@@ -1016,11 +986,8 @@ static void eth_stm32_mcast_filter(const struct device *dev, const struct ethern
1016986
static int eth_init_api_v2(const struct device *dev)
1017987
{
1018988
HAL_StatusTypeDef hal_ret = HAL_OK;
1019-
struct eth_stm32_hal_dev_data *dev_data;
1020-
ETH_HandleTypeDef *heth;
1021-
1022-
dev_data = dev->data;
1023-
heth = &dev_data->heth;
989+
struct eth_stm32_hal_dev_data *dev_data = dev->data;
990+
ETH_HandleTypeDef *heth = &dev_data->heth;
1024991

1025992
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32n6_ethernet)
1026993
for (int ch = 0; ch < ETH_DMA_CH_CNT; ch++) {
@@ -1173,21 +1140,10 @@ static void phy_link_state_changed(const struct device *phy_dev, struct phy_link
11731140

11741141
static void eth_iface_init(struct net_if *iface)
11751142
{
1176-
const struct device *dev;
1177-
struct eth_stm32_hal_dev_data *dev_data;
1143+
const struct device *dev = net_if_get_device(iface);
1144+
struct eth_stm32_hal_dev_data *dev_data = dev->data;
1145+
ETH_HandleTypeDef *heth = &dev_data->heth;
11781146
bool is_first_init = false;
1179-
ETH_HandleTypeDef *heth;
1180-
1181-
__ASSERT_NO_MSG(iface != NULL);
1182-
1183-
dev = net_if_get_device(iface);
1184-
__ASSERT_NO_MSG(dev != NULL);
1185-
1186-
dev_data = dev->data;
1187-
__ASSERT_NO_MSG(dev_data != NULL);
1188-
1189-
heth = &dev_data->heth;
1190-
__ASSERT_NO_MSG(heth != NULL);
11911147

11921148
if (dev_data->iface == NULL) {
11931149
dev_data->iface = iface;
@@ -1277,21 +1233,16 @@ static enum ethernet_hw_caps eth_stm32_hal_get_capabilities(const struct device
12771233
static int eth_stm32_hal_get_config(const struct device *dev, enum ethernet_config_type type,
12781234
struct ethernet_config *config)
12791235
{
1280-
int ret = -ENOTSUP;
1281-
struct eth_stm32_hal_dev_data *dev_data;
1282-
ETH_HandleTypeDef *heth;
1283-
1284-
dev_data = dev->data;
1285-
heth = &dev_data->heth;
1236+
struct eth_stm32_hal_dev_data *dev_data = dev->data;
12861237

12871238
switch (type) {
12881239
case ETHERNET_CONFIG_TYPE_MAC_ADDRESS:
12891240
memcpy(config->mac_address.addr, dev_data->mac_addr,
12901241
sizeof(config->mac_address.addr));
1291-
ret = 0;
1292-
break;
1293-
case ETHERNET_CONFIG_TYPE_PROMISC_MODE:
1242+
return 0;
12941243
#if defined(CONFIG_NET_PROMISCUOUS_MODE)
1244+
case ETHERNET_CONFIG_TYPE_PROMISC_MODE:
1245+
ETH_HandleTypeDef *heth = &dev_data->heth;
12951246
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
12961247
ETH_MACFilterConfigTypeDef MACFilterConf;
12971248

@@ -1305,26 +1256,21 @@ static int eth_stm32_hal_get_config(const struct device *dev, enum ethernet_conf
13051256
config->promisc_mode = false;
13061257
}
13071258
#endif /* CONFIG_ETH_STM32_HAL_API_V2 */
1308-
ret = 0;
1259+
return 0;
13091260
#endif /* CONFIG_NET_PROMISCUOUS_MODE */
1310-
break;
13111261
default:
13121262
break;
13131263
}
13141264

1315-
return ret;
1265+
return -ENOTSUP;
13161266
}
13171267

13181268
static int eth_stm32_hal_set_config(const struct device *dev,
13191269
enum ethernet_config_type type,
13201270
const struct ethernet_config *config)
13211271
{
1322-
int ret = -ENOTSUP;
1323-
struct eth_stm32_hal_dev_data *dev_data;
1324-
ETH_HandleTypeDef *heth;
1325-
1326-
dev_data = dev->data;
1327-
heth = &dev_data->heth;
1272+
struct eth_stm32_hal_dev_data *dev_data = dev->data;
1273+
ETH_HandleTypeDef *heth = &dev_data->heth;
13281274

13291275
switch (type) {
13301276
case ETHERNET_CONFIG_TYPE_MAC_ADDRESS:
@@ -1338,10 +1284,9 @@ static int eth_stm32_hal_set_config(const struct device *dev,
13381284
net_if_set_link_addr(dev_data->iface, dev_data->mac_addr,
13391285
sizeof(dev_data->mac_addr),
13401286
NET_LINK_ETHERNET);
1341-
ret = 0;
1342-
break;
1343-
case ETHERNET_CONFIG_TYPE_PROMISC_MODE:
1287+
return 0;
13441288
#if defined(CONFIG_NET_PROMISCUOUS_MODE)
1289+
case ETHERNET_CONFIG_TYPE_PROMISC_MODE:
13451290
#if defined(CONFIG_ETH_STM32_HAL_API_V2)
13461291
ETH_MACFilterConfigTypeDef MACFilterConf;
13471292

@@ -1357,19 +1302,18 @@ static int eth_stm32_hal_set_config(const struct device *dev,
13571302
heth->Instance->MACFFR &= ~ETH_MACFFR_PM;
13581303
}
13591304
#endif /* CONFIG_ETH_STM32_HAL_API_V2 */
1360-
ret = 0;
1305+
return 0;
13611306
#endif /* CONFIG_NET_PROMISCUOUS_MODE */
1362-
break;
13631307
#if defined(CONFIG_ETH_STM32_MULTICAST_FILTER)
13641308
case ETHERNET_CONFIG_TYPE_FILTER:
13651309
eth_stm32_mcast_filter(dev, &config->filter);
1366-
break;
1310+
return 0;
13671311
#endif /* CONFIG_ETH_STM32_MULTICAST_FILTER */
13681312
default:
13691313
break;
13701314
}
13711315

1372-
return ret;
1316+
return -ENOTSUP;
13731317
}
13741318

13751319
static const struct device *eth_stm32_hal_get_phy(const struct device *dev)

0 commit comments

Comments
 (0)