Skip to content

Commit 39859be

Browse files
takaswietiwai
authored andcommitted
firewire: cdev: use single object to dispatch event for request to IEC 61883-1 FCP region
The core function always passes the data of request to the callback of listener in any case. Additionally, the listener can maintain the lifetime of data by reference count. In character device, no need to duplicate the payload of request anymore to copy it to user space. This commit extends the lifetime of data to obsolete duplication of payload for request in character device. Signed-off-by: Takashi Sakamoto <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent e699600 commit 39859be

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

drivers/firewire/core-cdev.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ static void release_request(struct client *client,
651651
struct inbound_transaction_resource, resource);
652652

653653
if (r->is_fcp)
654-
kfree(r->data);
654+
fw_request_put(r->request);
655655
else
656656
fw_send_response(r->card, r->request, RCODE_CONFLICT_ERROR);
657657

@@ -669,12 +669,16 @@ static void handle_request(struct fw_card *card, struct fw_request *request,
669669
struct inbound_transaction_resource *r;
670670
struct inbound_transaction_event *e;
671671
size_t event_size0;
672-
void *fcp_frame = NULL;
673672
int ret;
674673

675674
/* card may be different from handler->client->device->card */
676675
fw_card_get(card);
677676

677+
// Extend the lifetime of data for request so that its payload is safely accessible in
678+
// the process context for the client.
679+
if (is_fcp)
680+
fw_request_get(request);
681+
678682
r = kmalloc(sizeof(*r), GFP_ATOMIC);
679683
e = kmalloc(sizeof(*e), GFP_ATOMIC);
680684
if (r == NULL || e == NULL)
@@ -686,18 +690,6 @@ static void handle_request(struct fw_card *card, struct fw_request *request,
686690
r->data = payload;
687691
r->length = length;
688692

689-
if (is_fcp) {
690-
/*
691-
* FIXME: Let core-transaction.c manage a
692-
* single reference-counted copy?
693-
*/
694-
fcp_frame = kmemdup(payload, length, GFP_ATOMIC);
695-
if (fcp_frame == NULL)
696-
goto failed;
697-
698-
r->data = fcp_frame;
699-
}
700-
701693
r->resource.release = release_request;
702694
ret = add_client_resource(handler->client, &r->resource, GFP_ATOMIC);
703695
if (ret < 0)
@@ -739,10 +731,11 @@ static void handle_request(struct fw_card *card, struct fw_request *request,
739731
failed:
740732
kfree(r);
741733
kfree(e);
742-
kfree(fcp_frame);
743734

744735
if (!is_fcp)
745736
fw_send_response(card, request, RCODE_CONFLICT_ERROR);
737+
else
738+
fw_request_put(request);
746739

747740
fw_card_put(card);
748741
}
@@ -818,7 +811,7 @@ static int ioctl_send_response(struct client *client, union ioctl_arg *arg)
818811
r = container_of(resource, struct inbound_transaction_resource,
819812
resource);
820813
if (r->is_fcp) {
821-
kfree(r->data);
814+
fw_request_put(r->request);
822815
goto out;
823816
}
824817

0 commit comments

Comments
 (0)