From nobody Mon Sep 15 03:01:01 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5269AC05027 for ; Fri, 20 Jan 2023 09:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbjATJEF (ORCPT ); Fri, 20 Jan 2023 04:04:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbjATJDz (ORCPT ); Fri, 20 Jan 2023 04:03:55 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3B6CEC4A for ; Fri, 20 Jan 2023 01:03:53 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4B57E5C0154; Fri, 20 Jan 2023 04:03:53 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 20 Jan 2023 04:03:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1674205433; x= 1674291833; bh=ofXt6LA5isnrTwDUYaXALKqLJ5c6lOkyPZo5vc9Gy7g=; b=b 1BRbngqLvU6QNPyFYJx70Ij6oJ6izykcupYX/KcOeJJpgfzlhJS+SaLtPHuvcibt QldRAp52Sdgq+GCfwflthHk+tzXrWyJ/H3fIUKrgT8KGjnFPgLGKDG7n7OlMTL0f VjQ5ARiH0IiLttBHaqbLNJCfUefX1f3fFkZORG3Tjcyov8Dcno3m14/Ly2S614lc Gu/C5SPshpF/VMNByDRsfqXAGoiQJ0VJdsCAs9BihuaCfuCGY5yMyefa7CwCcOcI Sy+Lpd9Vs8MhHknX9frwNB+bfpqCZlRznvW8H6pVSJDou7rFRfa4AqArauPiDKup QWT9q2RM02mY+zY+wZBfQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1674205433; x=1674291833; bh=ofXt6LA5isnrT wDUYaXALKqLJ5c6lOkyPZo5vc9Gy7g=; b=Rct60oA4KKTDoDwWjc0y3rp38AxHY nnXgDupAR1muiISEONGPaLHZjWYPTjDKogJOPPT7Za/Z/6aJoQaKbLyvJ4YrLyW2 M8P/OblK2A0ceHmBdZT3PjV7hzVPlLAvKlBeAYK3SNSsAMfALHeMAcosepZSwdV9 JsbVqN4l90EQFS7HqgdEjN0IpWid9S1rmdKWoKR9MlQv/jzMk+aahk6EpvzxpEdM KV/7q2phb/pv1Tn1lrPx4d0sKnH6v4RgRV+BC+0aQrPiAzQAeEfs9NCgCAeeRNSn Pb1N3325dv3B4q2KS71Z51iKewzSbIXIxT6sdCK2rmeWOqvRHDQnNFZxQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudduuddguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestd ekredtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgr khgrshhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgf ejuedvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhih esshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 20 Jan 2023 04:03:51 -0500 (EST) From: Takashi Sakamoto To: tiwai@suse.de, stefanr@s5r6.in-berlin.de Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org Subject: [PATCH 2/3] firewire: cdev: obsolete NULL check to detect IEC 61883-1 FCP region Date: Fri, 20 Jan 2023 18:03:43 +0900 Message-Id: <20230120090344.296451-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230120090344.296451-1-o-takashi@sakamocchi.jp> References: <20230120090344.296451-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In the character device, the listener to address space should distinguish whether the request is to IEC 61883-1 FCP region or not. The user space application needs to access to the object of request in enough later by read(2), while the core function releases the object of request in the FCP case after completing the callback to handler. The handler guarantees the access safe by some way. It's done by duplication of the object after NULL check to the request, since core function passes NULL in the FCP case. It's inconvenient since the object of request includes some helpful information. It's better to add another way to check whether the request is to FCP region or not. Conveniently the file of transaction layer includes local implementation for the purpose. This commit moves it to module local file and use it instead of the NULL check, then the result of check is stored to per-client data for the inbound transaction so that the result can be referred by later to release the data. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 16 +++++++--------- drivers/firewire/core-transaction.c | 20 ++++++++++---------- drivers/firewire/core.h | 6 ++++++ include/linux/firewire.h | 5 ++--- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 93dd80d8d4e1..7fa49e51bae8 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -111,6 +111,7 @@ struct inbound_transaction_resource { struct client_resource resource; struct fw_card *card; struct fw_request *request; + bool is_fcp; void *data; size_t length; }; @@ -643,18 +644,13 @@ static int ioctl_send_request(struct client *client, = union ioctl_arg *arg) client->device->max_speed); } =20 -static inline bool is_fcp_request(struct fw_request *request) -{ - return request =3D=3D NULL; -} - static void release_request(struct client *client, struct client_resource *resource) { struct inbound_transaction_resource *r =3D container_of(resource, struct inbound_transaction_resource, resource); =20 - if (is_fcp_request(r->request)) + if (r->is_fcp) kfree(r->data); else fw_send_response(r->card, r->request, RCODE_CONFLICT_ERROR); @@ -669,6 +665,7 @@ static void handle_request(struct fw_card *card, struct= fw_request *request, void *payload, size_t length, void *callback_data) { struct address_handler_resource *handler =3D callback_data; + bool is_fcp =3D is_in_fcp_region(offset, length); struct inbound_transaction_resource *r; struct inbound_transaction_event *e; size_t event_size0; @@ -685,10 +682,11 @@ static void handle_request(struct fw_card *card, stru= ct fw_request *request, =20 r->card =3D card; r->request =3D request; + r->is_fcp =3D is_fcp; r->data =3D payload; r->length =3D length; =20 - if (is_fcp_request(request)) { + if (is_fcp) { /* * FIXME: Let core-transaction.c manage a * single reference-counted copy? @@ -743,7 +741,7 @@ static void handle_request(struct fw_card *card, struct= fw_request *request, kfree(e); kfree(fcp_frame); =20 - if (!is_fcp_request(request)) + if (!is_fcp) fw_send_response(card, request, RCODE_CONFLICT_ERROR); =20 fw_card_put(card); @@ -819,7 +817,7 @@ static int ioctl_send_response(struct client *client, u= nion ioctl_arg *arg) =20 r =3D container_of(resource, struct inbound_transaction_resource, resource); - if (is_fcp_request(r->request)) { + if (r->is_fcp) { kfree(r->data); goto out; } diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index 83f61cf1aa8f..a9f70c96323e 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -535,12 +535,6 @@ const struct fw_address_region fw_unit_space_region = =3D { .start =3D 0xfffff0000900ULL, .end =3D 0x1000000000000ULL, }; #endif /* 0 */ =20 -static bool is_in_fcp_region(u64 offset, size_t length) -{ - return offset >=3D (CSR_REGISTER_BASE | CSR_FCP_COMMAND) && - offset + length <=3D (CSR_REGISTER_BASE | CSR_FCP_END); -} - /** * fw_core_add_address_handler() - register for incoming requests * @handler: callback @@ -822,12 +816,18 @@ static struct fw_request *allocate_request(struct fw_= card *card, return request; } =20 +/** + * fw_send_response: - send response packet for asynchronous transaction. + * @card: interface to send the response at. + * @request: firewire request data for the transaction. + * @rcode: response code to send. + * + * Submit a response packet into the asynchronous response transmission qu= eue. The @request + * is going to be released when the transmission successfully finishes lat= er. + */ void fw_send_response(struct fw_card *card, struct fw_request *request, int rcode) { - if (WARN_ONCE(!request, "invalid for FCP address handlers")) - return; - /* unified transaction or broadcast transaction: don't respond */ if (request->ack !=3D ACK_PENDING || HEADER_DESTINATION_IS_BROADCAST(request->request_header[0])) { @@ -935,7 +935,7 @@ static void handle_fcp_region_request(struct fw_card *c= ard, rcu_read_lock(); list_for_each_entry_rcu(handler, &address_handler_list, link) { if (is_enclosing_handler(handler, offset, request->length)) - handler->address_callback(card, NULL, tcode, + handler->address_callback(card, request, tcode, destination, source, p->generation, offset, request->data, diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index 78c99f1d27fa..eafa4eaae737 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h @@ -257,4 +257,10 @@ static inline bool is_ping_packet(u32 *data) return (data[0] & 0xc0ffffff) =3D=3D 0 && ~data[0] =3D=3D data[1]; } =20 +static inline bool is_in_fcp_region(u64 offset, size_t length) +{ + return offset >=3D (CSR_REGISTER_BASE | CSR_FCP_COMMAND) && + offset + length <=3D (CSR_REGISTER_BASE | CSR_FCP_END); +} + #endif /* _FIREWIRE_CORE_H */ diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 980019053e54..56505436d159 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -278,9 +278,8 @@ typedef void (*fw_transaction_callback_t)(struct fw_car= d *card, int rcode, * Otherwise there is a danger of recursion of inbound and outbound * transactions from and to the local node. * - * The callback is responsible that either fw_send_response() or kfree() - * is called on the @request, except for FCP registers for which the core - * takes care of that. + * The callback is responsible that fw_send_response() is called on the @r= equest, except for FCP + * registers for which the core takes care of that. */ typedef void (*fw_address_callback_t)(struct fw_card *card, struct fw_request *request, --=20 2.37.2