1
0
Fork 0
forked from nuttx/nuttx-update

driver/i3c: Fixed i3c pointer format to check null

Signed-off-by: yangshuyong <yangshuyong@xiaomi.com>
This commit is contained in:
yangshuyong 2024-04-03 10:57:12 +08:00 committed by Xiang Xiao
parent 7a48469e70
commit cffcccafc2
4 changed files with 44 additions and 43 deletions

View file

@ -88,7 +88,7 @@ int i3c_device_do_priv_xfers(FAR const struct i3c_device *dev,
void i3c_device_get_info(FAR const struct i3c_device *dev, void i3c_device_get_info(FAR const struct i3c_device *dev,
FAR struct i3c_device_info *info) FAR struct i3c_device_info *info)
{ {
if (!info) if (info == NULL)
{ {
return; return;
} }
@ -198,7 +198,7 @@ int i3c_device_request_ibi(FAR const struct i3c_device *dev,
{ {
int ret = -ENOENT; int ret = -ENOENT;
if (!req->handler || !req->num_slots) if (req->handler == NULL || !req->num_slots)
{ {
return -EINVAL; return -EINVAL;
} }

View file

@ -348,7 +348,7 @@ static int i3cdrvr_unlink(FAR struct inode *inode)
* Input Parameters: * Input Parameters:
* master - the lower half of an the controller object about I3C master * master - the lower half of an the controller object about I3C master
* driver. * driver.
* bus - The I3C bus number. This will be used as the I3C device minor * bus - The I3C bus number. This will be used as the I3C device minor
* number. The I3C character device will be registered as /dev/i3cN * number. The I3C character device will be registered as /dev/i3cN
* where N is the minor number * where N is the minor number
* *

View file

@ -358,7 +358,7 @@ i3c_master_alloc_i3c_dev(FAR struct i3c_master_controller *master,
FAR struct i3c_dev_desc *dev; FAR struct i3c_dev_desc *dev;
dev = kmm_zalloc(sizeof(*dev)); dev = kmm_zalloc(sizeof(*dev));
if (!dev) if (dev == NULL)
{ {
return NULL; return NULL;
} }
@ -378,7 +378,7 @@ static int i3c_master_rstdaa_locked(FAR struct i3c_master_controller *master,
struct i3c_ccc_cmd cmd; struct i3c_ccc_cmd cmd;
int ret; int ret;
if (!master) if (master == NULL)
{ {
return -EINVAL; return -EINVAL;
} }
@ -409,7 +409,7 @@ static int i3c_master_enec_disec_locked(
int ret; int ret;
events = i3c_ccc_cmd_dest_init(&dest, addr, sizeof(*events)); events = i3c_ccc_cmd_dest_init(&dest, addr, sizeof(*events));
if (!events) if (events == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -440,7 +440,7 @@ static int i3c_master_setda_locked(FAR struct i3c_master_controller *master,
} }
setda = i3c_ccc_cmd_dest_init(&dest, oldaddr, sizeof(*setda)); setda = i3c_ccc_cmd_dest_init(&dest, oldaddr, sizeof(*setda));
if (!setda) if (setda == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -471,7 +471,7 @@ static int i3c_master_getmrl_locked(FAR struct i3c_master_controller *master,
int ret; int ret;
mrl = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*mrl)); mrl = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*mrl));
if (!mrl) if (mrl == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -525,7 +525,7 @@ static int i3c_master_getmwl_locked(FAR struct i3c_master_controller *master,
int ret; int ret;
mwl = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*mwl)); mwl = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*mwl));
if (!mwl) if (mwl == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -562,7 +562,7 @@ static int i3c_master_getmxds_locked(
getmaxds = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, getmaxds = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
sizeof(*getmaxds)); sizeof(*getmaxds));
if (!getmaxds) if (getmaxds == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -606,7 +606,7 @@ static int i3c_master_gethdrcap_locked(
gethdrcap = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, gethdrcap = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
sizeof(*gethdrcap)); sizeof(*gethdrcap));
if (!gethdrcap) if (gethdrcap == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -642,7 +642,7 @@ static int i3c_master_getpid_locked(FAR struct i3c_master_controller *master,
int i; int i;
getpid = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*getpid)); getpid = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*getpid));
if (!getpid) if (getpid == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -676,7 +676,7 @@ static int i3c_master_getbcr_locked(FAR struct i3c_master_controller *master,
int ret; int ret;
getbcr = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*getbcr)); getbcr = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*getbcr));
if (!getbcr) if (getbcr == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -705,7 +705,7 @@ static int i3c_master_getdcr_locked(FAR struct i3c_master_controller *master,
int ret; int ret;
getdcr = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*getdcr)); getdcr = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr, sizeof(*getdcr));
if (!getdcr) if (getdcr == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -937,7 +937,7 @@ i3c_master_register_new_i3c_devs(FAR struct i3c_master_controller *master)
} }
desc->dev = kmm_zalloc(sizeof(*desc->dev)); desc->dev = kmm_zalloc(sizeof(*desc->dev));
if (!desc->dev) if (desc->dev == NULL)
{ {
continue; continue;
} }
@ -1018,7 +1018,7 @@ static int i3c_master_bus_init(FAR struct i3c_master_controller *master)
* complain if this was not the case. * complain if this was not the case.
*/ */
if (!master->this) if (master->this == NULL)
{ {
i3cerr("master_set_info() was not called in ->bus_init()\n"); i3cerr("master_set_info() was not called in ->bus_init()\n");
ret = -EINVAL; ret = -EINVAL;
@ -1110,12 +1110,12 @@ static int i3c_master_i2c_adapter_xfer(FAR struct i2c_master_s *i2c,
int ret; int ret;
uint16_t addr; uint16_t addr;
if (!xfers || !master || nxfers <= 0) if (xfers == NULL || master == NULL || nxfers <= 0)
{ {
return -EINVAL; return -EINVAL;
} }
if (!master->ops->i2c_xfers) if (master->ops->i2c_xfers == NULL)
{ {
return -ENOTSUP; return -ENOTSUP;
} }
@ -1150,7 +1150,7 @@ static void i3c_master_unregister_i3c_devs(
i3c_bus_for_each_i3cdev(&master->bus, i3cdev) i3c_bus_for_each_i3cdev(&master->bus, i3cdev)
{ {
if (!i3cdev->dev) if (i3cdev->dev == NULL)
{ {
continue; continue;
} }
@ -1194,15 +1194,16 @@ static void i3c_master_init_ibi_slot(FAR struct i3c_dev_desc *dev,
static int i3c_master_check_ops( static int i3c_master_check_ops(
FAR const struct i3c_master_controller_ops *ops) FAR const struct i3c_master_controller_ops *ops)
{ {
if (!ops || !ops->bus_init || !ops->priv_xfers || if (ops == NULL || ops->bus_init == NULL || ops->priv_xfers == NULL ||
!ops->send_ccc_cmd || !ops->do_daa || !ops->i2c_xfers) ops->send_ccc_cmd == NULL || ops->do_daa == NULL ||
ops->i2c_xfers == NULL)
{ {
return -EINVAL; return -EINVAL;
} }
if (ops->request_ibi && if (ops->request_ibi &&
(!ops->enable_ibi || !ops->disable_ibi || !ops->free_ibi || (ops->enable_ibi == NULL || ops->disable_ibi == NULL ||
!ops->recycle_ibi_slot)) ops->free_ibi == NULL || ops->recycle_ibi_slot == NULL))
{ {
return -EINVAL; return -EINVAL;
} }
@ -1264,7 +1265,7 @@ int i3c_master_send_ccc_cmd_locked(
{ {
int ret; int ret;
if (!cmd || !master) if (cmd == NULL || master == NULL)
{ {
return -EINVAL; return -EINVAL;
} }
@ -1275,12 +1276,12 @@ int i3c_master_send_ccc_cmd_locked(
return -EINVAL; return -EINVAL;
} }
if (!master->ops->send_ccc_cmd) if (master->ops->send_ccc_cmd == NULL)
{ {
return -ENOTSUP; return -ENOTSUP;
} }
if ((cmd->id & I3C_CCC_DIRECT) && (!cmd->dests || !cmd->ndests)) if ((cmd->id & I3C_CCC_DIRECT) && (cmd->dests == NULL || !cmd->ndests))
{ {
return -EINVAL; return -EINVAL;
} }
@ -1625,7 +1626,7 @@ int i3c_master_add_i3c_dev_locked(FAR struct i3c_master_controller *master,
int ret; int ret;
memset(&ibireq, 0, sizeof(struct i3c_ibi_setup)); memset(&ibireq, 0, sizeof(struct i3c_ibi_setup));
if (!master) if (master == NULL)
{ {
return -EINVAL; return -EINVAL;
} }
@ -1868,7 +1869,7 @@ i3c_generic_ibi_alloc_pool(FAR struct i3c_dev_desc *dev,
struct i3c_generic_ibi_pool *ret; struct i3c_generic_ibi_pool *ret;
pool = kmm_zalloc(sizeof(*pool)); pool = kmm_zalloc(sizeof(*pool));
if (!pool) if (pool == NULL)
{ {
return NULL; return NULL;
} }
@ -1877,7 +1878,7 @@ i3c_generic_ibi_alloc_pool(FAR struct i3c_dev_desc *dev,
list_initialize(&pool->pending); list_initialize(&pool->pending);
pool->slots = kmm_calloc(req->num_slots, sizeof(*slot)); pool->slots = kmm_calloc(req->num_slots, sizeof(*slot));
if (!pool->slots) if (pool->slots == NULL)
{ {
ret = NULL; ret = NULL;
goto err_free_pool; goto err_free_pool;
@ -1887,7 +1888,7 @@ i3c_generic_ibi_alloc_pool(FAR struct i3c_dev_desc *dev,
{ {
pool->payload_buf = kmm_calloc(req->num_slots, pool->payload_buf = kmm_calloc(req->num_slots,
req->max_payload_len); req->max_payload_len);
if (!pool->payload_buf) if (pool->payload_buf == NULL)
{ {
ret = NULL; ret = NULL;
goto err_free_pool; goto err_free_pool;
@ -1978,7 +1979,7 @@ void i3c_generic_ibi_recycle_slot(FAR struct i3c_generic_ibi_pool *pool,
FAR struct i3c_generic_ibi_slot *slot; FAR struct i3c_generic_ibi_slot *slot;
unsigned long flags; unsigned long flags;
if (!s) if (s == NULL)
{ {
return; return;
} }
@ -1995,18 +1996,18 @@ int i3c_dev_do_priv_xfers_locked(FAR struct i3c_dev_desc *dev,
{ {
FAR struct i3c_master_controller *master; FAR struct i3c_master_controller *master;
if (!dev) if (dev == NULL)
{ {
return -ENOENT; return -ENOENT;
} }
master = i3c_dev_get_master(dev); master = i3c_dev_get_master(dev);
if (!master || !xfers) if (master == NULL || xfers == NULL)
{ {
return -EINVAL; return -EINVAL;
} }
if (!master->ops->priv_xfers) if (master->ops->priv_xfers == NULL)
{ {
return -ENOTSUP; return -ENOTSUP;
} }
@ -2019,7 +2020,7 @@ int i3c_dev_disable_ibi_locked(FAR struct i3c_dev_desc *dev)
FAR struct i3c_master_controller *master; FAR struct i3c_master_controller *master;
int ret; int ret;
if (!dev->ibi) if (dev->ibi == NULL)
{ {
return -EINVAL; return -EINVAL;
} }
@ -2047,7 +2048,7 @@ int i3c_dev_enable_ibi_locked(FAR struct i3c_dev_desc *dev)
FAR struct i3c_master_controller *master = i3c_dev_get_master(dev); FAR struct i3c_master_controller *master = i3c_dev_get_master(dev);
int ret; int ret;
if (!dev->ibi) if (dev->ibi == NULL)
{ {
return -EINVAL; return -EINVAL;
} }
@ -2068,7 +2069,7 @@ int i3c_dev_request_ibi_locked(FAR struct i3c_dev_desc *dev,
FAR struct i3c_device_ibi_info *ibi; FAR struct i3c_device_ibi_info *ibi;
int ret; int ret;
if (!master->ops->request_ibi) if (master->ops->request_ibi == NULL)
{ {
return -ENOTSUP; return -ENOTSUP;
} }
@ -2079,7 +2080,7 @@ int i3c_dev_request_ibi_locked(FAR struct i3c_dev_desc *dev,
} }
ibi = kmm_zalloc(sizeof(*ibi)); ibi = kmm_zalloc(sizeof(*ibi));
if (!ibi) if (ibi == NULL)
{ {
return -ENOMEM; return -ENOMEM;
} }
@ -2105,7 +2106,7 @@ void i3c_dev_free_ibi_locked(FAR struct i3c_dev_desc *dev)
{ {
FAR struct i3c_master_controller *master = i3c_dev_get_master(dev); FAR struct i3c_master_controller *master = i3c_dev_get_master(dev);
if (!dev->ibi) if (dev->ibi == NULL)
{ {
return; return;
} }
@ -2225,7 +2226,7 @@ int i3c_master_register(FAR struct i3c_master_controller *master,
/* Expose I2C driver node so by the i2c_driver on our I3C Bus */ /* Expose I2C driver node so by the i2c_driver on our I3C Bus */
master->i2c.ops = &i3c_master_i2c_algo; master->i2c.ops = &i3c_master_i2c_algo;
i2c_register(&master->i2c, master->i2c_bus_id); ret = i2c_register(&master->i2c, master->i2c_bus_id);
if (ret < 0) if (ret < 0)
{ {
i3cerr("ERROR: Failed to register I2C%d.\n", master->i2c_bus_id); i3cerr("ERROR: Failed to register I2C%d.\n", master->i2c_bus_id);

View file

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef _INCLUDE_NUTTX_I3C_DRIVER_H #ifndef _INCLUDE_NUTTX_I3C_I3C_DRIVER_H
#define _INCLUDE_NUTTX_I3C_DRIVER_H #define _INCLUDE_NUTTX_I3C_I3C_DRIVER_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -174,4 +174,4 @@ int i3c_register(FAR struct i3c_master_controller *master, int bus);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif
#endif /* _INCLUDE_NUTTX_I3C_DRIVER_H */ #endif /* _INCLUDE_NUTTX_I3C_I3C_DRIVER_H */