device: only increase the ref_count when device is truly opened
This commit is contained in:
parent
1dc376b2f4
commit
dc366ecf7a
12
src/device.c
12
src/device.c
|
@ -239,11 +239,6 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
|
||||||
return -RT_EBUSY;
|
return -RT_EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->ref_count++;
|
|
||||||
/* don't let bad things happen silently. If you are bitten by this assert,
|
|
||||||
* please set the ref_count to a bigger type. */
|
|
||||||
RT_ASSERT(dev->ref_count != 0);
|
|
||||||
|
|
||||||
/* call device open interface */
|
/* call device open interface */
|
||||||
if (dev->open != RT_NULL)
|
if (dev->open != RT_NULL)
|
||||||
{
|
{
|
||||||
|
@ -252,8 +247,15 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
|
||||||
|
|
||||||
/* set open flag */
|
/* set open flag */
|
||||||
if (result == RT_EOK || result == -RT_ENOSYS)
|
if (result == RT_EOK || result == -RT_ENOSYS)
|
||||||
|
{
|
||||||
dev->open_flag = oflag | RT_DEVICE_OFLAG_OPEN;
|
dev->open_flag = oflag | RT_DEVICE_OFLAG_OPEN;
|
||||||
|
|
||||||
|
dev->ref_count++;
|
||||||
|
/* don't let bad things happen silently. If you are bitten by this assert,
|
||||||
|
* please set the ref_count to a bigger type. */
|
||||||
|
RT_ASSERT(dev->ref_count != 0);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_device_open);
|
RTM_EXPORT(rt_device_open);
|
||||||
|
|
Loading…
Reference in New Issue