From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Kuen-Han Tsai <khtsai@google.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] usb: gadget: f_tcm: Use auto-cleanup for usb_request
Date: Thu, 30 Oct 2025 16:33:33 +0100 [thread overview]
Message-ID: <2025103010-awkward-gentleman-150d@gregkh> (raw)
In-Reply-To: <20251030-auto-cleanup-v1-1-db30584fadfd@google.com>
On Thu, Oct 30, 2025 at 11:14:19PM +0800, Kuen-Han Tsai wrote:
> Refactor f_tcm.c to use auto-cleanup mechanism for usb_request
> allocations in bot_prepare_reqs(), uasp_alloc_stream_res(), and
> uasp_alloc_cmd().
Using guards are great for new code, or for bug fixes, but please don't
just refactor code to use them for the sake of using them. It makes it
hard to review and justify the churn, especially when there is almost no
code savings here at all.
> The explicit nullification of fu->..._req and stream->..._req pointers
> on error is no longer needed. This is safe because these pointers are
> only updated after all allocations within the function have succeeded.
> If an error occurs, the fu structure members retain their previous
> value, and the existing cleanup functions like bot_cleanup_old_alt() and
> uasp_cleanup_old_alt() already handle stale pointers in the fu
> structure.
This seems to imply this is really fragile, and tricky, and maybe not
worth it?
The comment you added kind of enforces that feeling:
> + fu->bot_req_in = no_free_ptr(bot_req_in);
> + fu->bot_req_out = no_free_ptr(bot_req_out);
> +
> + /* This line is placed here because free_usb_request also frees its
> + * buffer, which in this case points to the static fu->bot_status.csw.
> + */
Which is "this line"?
> + status_req->buf = &fu->bot_status.csw;
This one?
> + status_req->length = US_BULK_CS_WRAP_LEN;
Or that one?
Using guards for buffers for other structures is rough, as you have seen
here, I don't really see the benefit at all, do you?
thanks,
greg k-h
next prev parent reply other threads:[~2025-10-30 15:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 15:14 [PATCH 0/2] usb: gadget: Auto-cleanup usb_request in f_loopback, f_tcm Kuen-Han Tsai
2025-10-30 15:14 ` [PATCH 1/2] usb: gadget: f_tcm: Use auto-cleanup for usb_request Kuen-Han Tsai
2025-10-30 15:33 ` Greg Kroah-Hartman [this message]
2025-11-03 9:54 ` Kuen-Han Tsai
2025-10-30 15:14 ` [PATCH 2/2] usb: gadget: f_loopback: " Kuen-Han Tsai
2025-10-30 15:34 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2025103010-awkward-gentleman-150d@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=Thinh.Nguyen@synopsys.com \
--cc=khtsai@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox