Skip to content

Commit ced2da3

Browse files
committed
firewire: core: add helper functions to convert to parent resource structure
All of local resource structure commonly have data of client_resource type in its first member. This design sometimes requires usage of container_of to retrieve parent structure by the first member. This commit adds some helper functions for this purpose. Link: https://lore.kernel.org/r/20240812235210.28458-3-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent 3b443fe commit ced2da3

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

drivers/firewire/core-cdev.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,26 @@ struct iso_resource {
139139
struct iso_resource_event *e_alloc, *e_dealloc;
140140
};
141141

142+
static struct address_handler_resource *to_address_handler_resource(struct client_resource *resource)
143+
{
144+
return container_of(resource, struct address_handler_resource, resource);
145+
}
146+
147+
static struct inbound_transaction_resource *to_inbound_transaction_resource(struct client_resource *resource)
148+
{
149+
return container_of(resource, struct inbound_transaction_resource, resource);
150+
}
151+
152+
static struct descriptor_resource *to_descriptor_resource(struct client_resource *resource)
153+
{
154+
return container_of(resource, struct descriptor_resource, resource);
155+
}
156+
157+
static struct iso_resource *to_iso_resource(struct client_resource *resource)
158+
{
159+
return container_of(resource, struct iso_resource, resource);
160+
}
161+
142162
static void release_iso_resource(struct client *, struct client_resource *);
143163

144164
static void schedule_iso_resource(struct iso_resource *r, unsigned long delay)
@@ -151,8 +171,7 @@ static void schedule_iso_resource(struct iso_resource *r, unsigned long delay)
151171
static void schedule_if_iso_resource(struct client_resource *resource)
152172
{
153173
if (resource->release == release_iso_resource)
154-
schedule_iso_resource(container_of(resource,
155-
struct iso_resource, resource), 0);
174+
schedule_iso_resource(to_iso_resource(resource), 0);
156175
}
157176

158177
/*
@@ -682,8 +701,7 @@ static int ioctl_send_request(struct client *client, union ioctl_arg *arg)
682701
static void release_request(struct client *client,
683702
struct client_resource *resource)
684703
{
685-
struct inbound_transaction_resource *r = container_of(resource,
686-
struct inbound_transaction_resource, resource);
704+
struct inbound_transaction_resource *r = to_inbound_transaction_resource(resource);
687705

688706
if (r->is_fcp)
689707
fw_request_put(r->request);
@@ -793,8 +811,7 @@ static void handle_request(struct fw_card *card, struct fw_request *request,
793811
static void release_address_handler(struct client *client,
794812
struct client_resource *resource)
795813
{
796-
struct address_handler_resource *r =
797-
container_of(resource, struct address_handler_resource, resource);
814+
struct address_handler_resource *r = to_address_handler_resource(resource);
798815

799816
fw_core_remove_address_handler(&r->handler);
800817
kfree(r);
@@ -858,8 +875,7 @@ static int ioctl_send_response(struct client *client, union ioctl_arg *arg)
858875
release_request, &resource) < 0)
859876
return -EINVAL;
860877

861-
r = container_of(resource, struct inbound_transaction_resource,
862-
resource);
878+
r = to_inbound_transaction_resource(resource);
863879
if (r->is_fcp) {
864880
fw_request_put(r->request);
865881
goto out;
@@ -893,8 +909,7 @@ static int ioctl_initiate_bus_reset(struct client *client, union ioctl_arg *arg)
893909
static void release_descriptor(struct client *client,
894910
struct client_resource *resource)
895911
{
896-
struct descriptor_resource *r =
897-
container_of(resource, struct descriptor_resource, resource);
912+
struct descriptor_resource *r = to_descriptor_resource(resource);
898913

899914
fw_core_remove_descriptor(&r->descriptor);
900915
kfree(r);
@@ -1387,8 +1402,7 @@ static void iso_resource_work(struct work_struct *work)
13871402
static void release_iso_resource(struct client *client,
13881403
struct client_resource *resource)
13891404
{
1390-
struct iso_resource *r =
1391-
container_of(resource, struct iso_resource, resource);
1405+
struct iso_resource *r = to_iso_resource(resource);
13921406

13931407
guard(spinlock_irq)(&client->lock);
13941408

0 commit comments

Comments
 (0)