Skip to content

Commit 775712d

Browse files
sayoojkkarunkartben
authored andcommitted
include: zephyr: net: Add NULL checks for phy API calls
Add missing NULL checks to the APIs in phy.h Signed-off-by: Sayooj K Karun <[email protected]>
1 parent 8aed2a1 commit 775712d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

include/zephyr/net/phy.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/*
88
* Copyright (c) 2021 IP-Logix Inc.
99
* Copyright 2022 NXP
10+
* Copyright (c) 2025 Aerlync Labs Inc.
1011
*
1112
* SPDX-License-Identifier: Apache-2.0
1213
*/
@@ -23,6 +24,7 @@
2324
*/
2425
#include <zephyr/types.h>
2526
#include <zephyr/device.h>
27+
#include <errno.h>
2628

2729
#ifdef __cplusplus
2830
extern "C" {
@@ -209,6 +211,10 @@ static inline int phy_configure_link(const struct device *dev, enum phy_link_spe
209211
{
210212
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
211213

214+
if (api->cfg_link == NULL) {
215+
return -ENOSYS;
216+
}
217+
212218
return api->cfg_link(dev, speeds);
213219
}
214220

@@ -229,6 +235,10 @@ static inline int phy_get_link_state(const struct device *dev, struct phy_link_s
229235
{
230236
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
231237

238+
if (api->get_link == NULL) {
239+
return -ENOSYS;
240+
}
241+
232242
return api->get_link(dev, state);
233243
}
234244

@@ -251,6 +261,10 @@ static inline int phy_link_callback_set(const struct device *dev, phy_callback_t
251261
{
252262
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
253263

264+
if (api->link_cb_set == NULL) {
265+
return -ENOSYS;
266+
}
267+
254268
return api->link_cb_set(dev, callback, user_data);
255269
}
256270

@@ -270,6 +284,10 @@ static inline int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t
270284
{
271285
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
272286

287+
if (api->read == NULL) {
288+
return -ENOSYS;
289+
}
290+
273291
return api->read(dev, reg_addr, value);
274292
}
275293

@@ -289,6 +307,10 @@ static inline int phy_write(const struct device *dev, uint16_t reg_addr, uint32_
289307
{
290308
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
291309

310+
if (api->write == NULL) {
311+
return -ENOSYS;
312+
}
313+
292314
return api->write(dev, reg_addr, value);
293315
}
294316

@@ -310,6 +332,10 @@ static inline int phy_read_c45(const struct device *dev, uint8_t devad, uint16_t
310332
{
311333
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
312334

335+
if (api->read_c45 == NULL) {
336+
return -ENOSYS;
337+
}
338+
313339
return api->read_c45(dev, devad, regad, data);
314340
}
315341

@@ -331,6 +357,10 @@ static inline int phy_write_c45(const struct device *dev, uint8_t devad, uint16_
331357
{
332358
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
333359

360+
if (api->write_c45 == NULL) {
361+
return -ENOSYS;
362+
}
363+
334364
return api->write_c45(dev, devad, regad, data);
335365
}
336366

@@ -349,6 +379,10 @@ static inline int phy_set_plca_cfg(const struct device *dev, struct phy_plca_cfg
349379
{
350380
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
351381

382+
if (api->set_plca_cfg == NULL) {
383+
return -ENOSYS;
384+
}
385+
352386
return api->set_plca_cfg(dev, plca_cfg);
353387
}
354388

@@ -367,6 +401,10 @@ static inline int phy_get_plca_cfg(const struct device *dev, struct phy_plca_cfg
367401
{
368402
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
369403

404+
if (api->get_plca_cfg == NULL) {
405+
return -ENOSYS;
406+
}
407+
370408
return api->get_plca_cfg(dev, plca_cfg);
371409
}
372410

@@ -385,6 +423,10 @@ static inline int phy_get_plca_sts(const struct device *dev, bool *plca_status)
385423
{
386424
const struct ethphy_driver_api *api = (const struct ethphy_driver_api *)dev->api;
387425

426+
if (api->get_plca_sts == NULL) {
427+
return -ENOSYS;
428+
}
429+
388430
return api->get_plca_sts(dev, plca_status);
389431
}
390432

0 commit comments

Comments
 (0)