1.优化检测逻辑。

This commit is contained in:
MacRsh
2023-09-26 17:54:47 +08:00
parent f4b0cf470d
commit e39e69a929

View File

@@ -226,18 +226,20 @@ mr_err_t mr_device_ioctl(mr_device_t device, int cmd, void *args)
MR_ASSERT(device != MR_NULL); MR_ASSERT(device != MR_NULL);
MR_ASSERT(device->object.type == Mr_Object_Type_Device); MR_ASSERT(device->object.type == Mr_Object_Type_Device);
/* Call the ioctl operation, if provided */ /* Check if the ioctl operation is supported */
if (device->ops->ioctl != MR_NULL) if (device->ops->ioctl == MR_NULL)
{ {
ret = device->ops->ioctl(device, cmd, args); MR_DEBUG_D(DEBUG_TAG, "[%s] ioctl [%x] failed: [%d]\r\n", device->object.name, cmd, -MR_ERR_UNSUPPORTED);
if (ret != MR_ERR_OK) return -MR_ERR_UNSUPPORTED;
{
MR_DEBUG_D(DEBUG_TAG, "[%s] ioctl [%x] failed: [%d]\r\n", device->object.name, cmd, ret);
}
return ret;
} }
return -MR_ERR_UNSUPPORTED; /* Call the ioctl operation */
ret = device->ops->ioctl(device, cmd, args);
if (ret != MR_ERR_OK)
{
MR_DEBUG_D(DEBUG_TAG, "[%s] ioctl [%x] failed: [%d]\r\n", device->object.name, cmd, ret);
}
return ret;
} }
/** /**
@@ -259,8 +261,9 @@ mr_ssize_t mr_device_read(mr_device_t device, mr_off_t pos, void *buffer, mr_siz
MR_ASSERT(buffer != MR_NULL); MR_ASSERT(buffer != MR_NULL);
/* Check if the device is closed or unsupported */ /* Check if the device is closed or unsupported */
if ((device->ref_count == 0) || ((device->oflags & MR_DEVICE_OFLAG_RDONLY) == 0)) if ((device->oflags & MR_DEVICE_OFLAG_RDONLY) == MR_FALSE)
{ {
MR_DEBUG_D(DEBUG_TAG, "[%s] read [%d] failed: [%d]\r\n", device->object.name, pos, -MR_ERR_UNSUPPORTED);
return -MR_ERR_UNSUPPORTED; return -MR_ERR_UNSUPPORTED;
} }
@@ -293,8 +296,9 @@ mr_ssize_t mr_device_write(mr_device_t device, mr_off_t pos, const void *buffer,
MR_ASSERT(buffer != MR_NULL); MR_ASSERT(buffer != MR_NULL);
/* Check if the device is closed or unsupported */ /* Check if the device is closed or unsupported */
if ((device->ref_count == 0) || ((device->oflags & MR_DEVICE_OFLAG_WRONLY) == 0)) if ((device->oflags & MR_DEVICE_OFLAG_WRONLY) == MR_FALSE)
{ {
MR_DEBUG_D(DEBUG_TAG, "[%s] write [%d] failed: [%d]\r\n", device->object.name, pos, -MR_ERR_UNSUPPORTED);
return -MR_ERR_UNSUPPORTED; return -MR_ERR_UNSUPPORTED;
} }