diff --git a/components/vbus/vbus_chnx.c b/components/vbus/vbus_chnx.c index d9bb3e4d46..12b6af340e 100644 --- a/components/vbus/vbus_chnx.c +++ b/components/vbus/vbus_chnx.c @@ -231,13 +231,14 @@ void rt_vbus_chnx_register_disconn(rt_device_t dev, rt_vbus_event_listener indi, void *ctx) { - struct rt_vbus_dev *vdev = dev->user_data; + if (dev && dev->user_data) + { + struct rt_vbus_dev *vdev = dev->user_data; + RT_ASSERT(vdev->chnr != 0); - RT_ASSERT(vdev->chnr != 0); - - if (vdev) rt_vbus_register_listener(vdev->chnr, RT_VBUS_EVENT_ID_DISCONN, indi, ctx); + } } #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))