staging: vchiq_core: Bulk waiter should not piggy back on bulk userdata

Currently, struct bulk_waiter is allocated for VCHIQ_BULK_MODE_BLOCKING
bulk transfer and its pointer is assigned to vchiq_bulk->userdata. Avoid
this kind of piggybacking and introduce a dedicate 'waiter' member in
struct vchiq_bulk.

The 'userdata' is meant for VCHIQ_BULK_MODE_CALLBACK mode, to pass user
specified parameter to the actual callback function.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Link: https://lore.kernel.org/r/20241023110406.885199-3-umang.jain@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Umang Jain
2024-10-23 16:34:02 +05:30
committed by Greg Kroah-Hartman
parent 5e12a53902
commit 016856c1a5
4 changed files with 12 additions and 10 deletions

View File

@@ -594,7 +594,7 @@ vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handl
* Cancel the signal when the transfer completes.
*/
spin_lock(&service->state->bulk_waiter_spinlock);
bulk->userdata = NULL;
bulk->waiter = NULL;
spin_unlock(&service->state->bulk_waiter_spinlock);
}
}
@@ -604,7 +604,7 @@ vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handl
return -ENOMEM;
}
bulk_params->userdata = &waiter->bulk_waiter;
bulk_params->waiter = &waiter->bulk_waiter;
ret = vchiq_bulk_xfer_blocking(instance, handle, bulk_params);
if ((ret != -EAGAIN) || fatal_signal_pending(current) || !waiter->bulk_waiter.bulk) {
@@ -613,7 +613,7 @@ vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handl
if (bulk) {
/* Cancel the signal when the transfer completes. */
spin_lock(&service->state->bulk_waiter_spinlock);
bulk->userdata = NULL;
bulk->waiter = NULL;
spin_unlock(&service->state->bulk_waiter_spinlock);
}
kfree(waiter);

View File

@@ -1330,7 +1330,7 @@ static int service_notify_bulk(struct vchiq_service *service,
struct bulk_waiter *waiter;
spin_lock(&service->state->bulk_waiter_spinlock);
waiter = bulk->userdata;
waiter = bulk->waiter;
if (waiter) {
waiter->actual = bulk->actual;
complete(&waiter->event);
@@ -3035,7 +3035,7 @@ vchiq_bulk_xfer_queue_msg_killable(struct vchiq_service *service,
int payload[2];
if (bulk_params->mode == VCHIQ_BULK_MODE_BLOCKING) {
bulk_waiter = bulk_params->userdata;
bulk_waiter = bulk_params->waiter;
init_completion(&bulk_waiter->event);
bulk_waiter->actual = 0;
bulk_waiter->bulk = NULL;
@@ -3064,6 +3064,7 @@ vchiq_bulk_xfer_queue_msg_killable(struct vchiq_service *service,
/* Initiliaze the 'bulk' slot with bulk parameters passed in. */
bulk->mode = bulk_params->mode;
bulk->dir = bulk_params->dir;
bulk->waiter = bulk_params->waiter;
bulk->userdata = bulk_params->userdata;
bulk->size = bulk_params->size;
bulk->offset = bulk_params->offset;
@@ -3532,7 +3533,7 @@ vchiq_bulk_xfer_callback(struct vchiq_instance *instance, unsigned int handle,
*/
int
vchiq_bulk_xfer_waiting(struct vchiq_instance *instance,
unsigned int handle, struct bulk_waiter *userdata)
unsigned int handle, struct bulk_waiter *waiter)
{
struct vchiq_service *service = find_service_by_handle(instance, handle);
struct bulk_waiter *bulk_waiter;
@@ -3541,7 +3542,7 @@ vchiq_bulk_xfer_waiting(struct vchiq_instance *instance,
if (!service)
return -EINVAL;
if (!userdata)
if (!waiter)
goto error_exit;
if (service->srvstate != VCHIQ_SRVSTATE_OPEN)
@@ -3550,7 +3551,7 @@ vchiq_bulk_xfer_waiting(struct vchiq_instance *instance,
if (vchiq_check_service(service))
goto error_exit;
bulk_waiter = userdata;
bulk_waiter = waiter;
vchiq_service_put(service);

View File

@@ -115,6 +115,7 @@ struct vchiq_bulk {
short mode;
short dir;
void *userdata;
struct bulk_waiter *waiter;
dma_addr_t dma_addr;
int size;
void *remote_data;

View File

@@ -307,7 +307,7 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
bulk_params.mode = args->mode;
bulk_params.size = args->size;
bulk_params.dir = dir;
bulk_params.userdata = &waiter->bulk_waiter;
bulk_params.waiter = &waiter->bulk_waiter;
status = vchiq_bulk_xfer_blocking(instance, args->handle,
&bulk_params);
@@ -354,7 +354,7 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
if (waiter->bulk_waiter.bulk) {
/* Cancel the signal when the transfer completes. */
spin_lock(&service->state->bulk_waiter_spinlock);
waiter->bulk_waiter.bulk->userdata = NULL;
waiter->bulk_waiter.bulk->waiter = NULL;
spin_unlock(&service->state->bulk_waiter_spinlock);
}
kfree(waiter);