Merge branch 'ib/5.17-cros-ec-keyb' into next
[platform/kernel/linux-starfive.git] / drivers / usb / gadget / function / rndis.c
index b7ccf18..713efd9 100644 (file)
@@ -640,6 +640,7 @@ static int rndis_set_response(struct rndis_params *params,
        BufLength = le32_to_cpu(buf->InformationBufferLength);
        BufOffset = le32_to_cpu(buf->InformationBufferOffset);
        if ((BufLength > RNDIS_MAX_TOTAL_SIZE) ||
+           (BufOffset > RNDIS_MAX_TOTAL_SIZE) ||
            (BufOffset + 8 >= RNDIS_MAX_TOTAL_SIZE))
                    return -EINVAL;
 
@@ -922,6 +923,7 @@ struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v)
        params->resp_avail = resp_avail;
        params->v = v;
        INIT_LIST_HEAD(&params->resp_queue);
+       spin_lock_init(&params->resp_lock);
        pr_debug("%s: configNr = %d\n", __func__, i);
 
        return params;
@@ -1015,12 +1017,14 @@ void rndis_free_response(struct rndis_params *params, u8 *buf)
 {
        rndis_resp_t *r, *n;
 
+       spin_lock(&params->resp_lock);
        list_for_each_entry_safe(r, n, &params->resp_queue, list) {
                if (r->buf == buf) {
                        list_del(&r->list);
                        kfree(r);
                }
        }
+       spin_unlock(&params->resp_lock);
 }
 EXPORT_SYMBOL_GPL(rndis_free_response);
 
@@ -1030,14 +1034,17 @@ u8 *rndis_get_next_response(struct rndis_params *params, u32 *length)
 
        if (!length) return NULL;
 
+       spin_lock(&params->resp_lock);
        list_for_each_entry_safe(r, n, &params->resp_queue, list) {
                if (!r->send) {
                        r->send = 1;
                        *length = r->length;
+                       spin_unlock(&params->resp_lock);
                        return r->buf;
                }
        }
 
+       spin_unlock(&params->resp_lock);
        return NULL;
 }
 EXPORT_SYMBOL_GPL(rndis_get_next_response);
@@ -1054,7 +1061,9 @@ static rndis_resp_t *rndis_add_response(struct rndis_params *params, u32 length)
        r->length = length;
        r->send = 0;
 
+       spin_lock(&params->resp_lock);
        list_add_tail(&r->list, &params->resp_queue);
+       spin_unlock(&params->resp_lock);
        return r;
 }