usb_disk: fix SMAP violation for B_GET_MEDIA_STATUS ioctl
should fix #17283. To be tested. Change-Id: If594129a6e16b50c314efa2a7bb1d18e01cdad15 Reviewed-on: https://review.haiku-os.org/c/haiku/+/4505 Tested-by: Commit checker robot <[email protected]> Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <fs/devfs.h>
|
#include <fs/devfs.h>
|
||||||
|
#include <syscall_restart.h>
|
||||||
#include <util/AutoLock.h>
|
#include <util/AutoLock.h>
|
||||||
|
|
||||||
#include "scsi_sense.h"
|
#include "scsi_sense.h"
|
||||||
@@ -1794,18 +1795,24 @@ usb_disk_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
|||||||
case B_GET_MEDIA_STATUS:
|
case B_GET_MEDIA_STATUS:
|
||||||
{
|
{
|
||||||
err_act action = err_act_ok;
|
err_act action = err_act_ok;
|
||||||
|
status_t ready;
|
||||||
for (uint32 tries = 0; tries < 3; tries++) {
|
for (uint32 tries = 0; tries < 3; tries++) {
|
||||||
status_t ready = usb_disk_test_unit_ready(lun, &action);
|
ready = usb_disk_test_unit_ready(lun, &action);
|
||||||
if (ready == B_OK || ready == B_DEV_NO_MEDIA
|
if (ready == B_OK || ready == B_DEV_NO_MEDIA
|
||||||
|| (action != err_act_retry
|
|| (action != err_act_retry
|
||||||
&& action != err_act_many_retries)) {
|
&& action != err_act_many_retries)) {
|
||||||
*(status_t *)buffer = ready;
|
if (IS_USER_ADDRESS(buffer)) {
|
||||||
|
if (user_memcpy(buffer, &ready, sizeof(status_t)) != B_OK)
|
||||||
|
return B_BAD_ADDRESS;
|
||||||
|
} else if (is_called_via_syscall()) {
|
||||||
|
return B_BAD_ADDRESS;
|
||||||
|
} else
|
||||||
|
*(status_t *)buffer = ready;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snooze(500000);
|
snooze(500000);
|
||||||
}
|
}
|
||||||
TRACE("B_GET_MEDIA_STATUS: 0x%08" B_PRIx32 "\n",
|
TRACE("B_GET_MEDIA_STATUS: 0x%08" B_PRIx32 "\n", ready);
|
||||||
*(status_t *)buffer);
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user