1.安全优化。

This commit is contained in:
MacRsh
2024-01-18 07:57:24 +08:00
parent 9c8e16a9ed
commit bbf06b160d
2 changed files with 9 additions and 6 deletions

View File

@@ -209,8 +209,9 @@ static ssize_t mr_pwm_write(struct mr_dev *dev, int off, const void *buf, size_t
for (wr_size = 0; wr_size < size; wr_size += sizeof(*wr_buf))
{
/* Calculate the compare value */
uint32_t compare_value = (uint32_t)(((float)*wr_buf / 1000000.0f) * (float)(pwm->period));
MR_BOUND(compare_value, 0, pwm->period);
uint32_t compare_value = MR_BOUND((uint32_t)(((float)*wr_buf / 1000000.0f) * (float)(pwm->period)),
0,
pwm->period);
ops->write(pwm, off, compare_value);
wr_buf++;
}

View File

@@ -388,11 +388,13 @@ MR_INLINE ssize_t dev_ioctl(struct mr_dev *dev, int desc, int off, int cmd, void
{
if (args != MR_NULL)
{
int *path = (int *)args;
char *buf = (char *)path[0];
size_t bufsz = (size_t)path[1];
struct
{
char *buf;
size_t bufsz;
} *path = args;
return dev_get_path(dev, buf, bufsz);
return dev_get_path(dev, path->buf, path->bufsz);
}
return MR_EINVAL;
}