Linux USB
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Crescent Hsieh <crescentcy.hsieh@moxa.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	FangpingFP.Cheng@moxa.com, Epson.Chiang@moxa.com
Subject: Re: [PATCH v2 1/4] USB: serial: mxuport: clean up firmware version handling
Date: Tue, 21 Jul 2026 16:34:06 +0200	[thread overview]
Message-ID: <al-DXpI52HuWBNwG@hovoldconsulting.com> (raw)
In-Reply-To: <20260623080138.166398-3-crescentcy.hsieh@moxa.com>

On Tue, Jun 23, 2026 at 04:01:36PM +0800, Crescent Hsieh wrote:
> Add a small helper for parsing firmware versions and use it for the
> bundled firmware image. This avoids open-coded firmware image offsets
> in probe() and validates the image size before reading the version
> bytes.
> 
> Keep the existing version comparison policy unchanged, but store the
> version components explicitly so that the version can be printed
> without unpacking a raw integer.
> 
> Print the firmware version fields in decimal, as these fields represent
> readable version components rather than hexadecimal values.
> 
> Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
> ---

Thanks for the v2. You seem to have addressed all my comments on v1 of
the series, which is unfortunately not as common as I wish it were. :)

> @@ -82,7 +95,6 @@
>  
>  #define RQ_VENDOR_RESET_DEVICE		0x23 /* Try to reset the device */
>  #define RQ_VENDOR_QUERY_FW_CONFIG	0x24
> -

Nit: this is an unrelated change

I see you add another define here in the next patch, but perhaps you
should keep the newline separators before and after that one.

>  #define RQ_VENDOR_GET_VERSION		0x81 /* Get firmware version */
>  #define RQ_VENDOR_GET_PAGE		0x82 /* Read flash page */
>  #define RQ_VENDOR_GET_ROM_PROC		0x83 /* Get ROM process state */
> @@ -970,8 +982,32 @@ static int mxuport_calc_num_ports(struct usb_serial *serial,
>  	return num_ports;
>  }
>  
> +static void mxuport_set_fw_version(struct mxuport_fw_version *version,
> +				   u8 major, u8 minor, u8 build)

The naming is a bit unfortunate as this is not an inverse of
mxuport_get_fw_version() but that should be ok.

> +{
> +	version->major = major;
> +	version->minor = minor;
> +	version->build = build;
> +	version->value = (major << 16) | (minor << 8) | build;
> +}
> +
> +static int mxuport_parse_fw_version(const struct firmware *fw,
> +				    const u16 *offsets,
> +				    struct mxuport_fw_version *version)
> +{
> +	if (fw->size <= offsets[0] || fw->size <= offsets[1] ||
> +	    fw->size <= offsets[2])
> +		return -EINVAL;

I just merged this sanity check:

	https://lore.kernel.org/all/20260715084611.45995-1-pengpeng@iscas.ac.cn/

so you may want to rebase on my usb-linus branch if there is a v3,
otherwise I can fix it up.

	https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git/log/?h=usb-linus

> +
> +	mxuport_set_fw_version(version, fw->data[offsets[0]],
> +			       fw->data[offsets[1]], fw->data[offsets[2]]);
> +
> +	return 0;
> +}
> +
>  /* Get the version of the firmware currently running. */
> -static int mxuport_get_fw_version(struct usb_serial *serial, u32 *version)
> +static int mxuport_get_fw_version(struct usb_serial *serial,
> +				  struct mxuport_fw_version *version)
>  {
>  	u8 *ver_buf;
>  	int err;
> @@ -988,7 +1024,7 @@ static int mxuport_get_fw_version(struct usb_serial *serial, u32 *version)
>  		goto out;
>  	}
>  
> -	*version = (ver_buf[0] << 16) | (ver_buf[1] << 8) | ver_buf[2];
> +	mxuport_set_fw_version(version, ver_buf[0], ver_buf[1], ver_buf[2]);
>  	err = 0;
>  out:
>  	kfree(ver_buf);
> @@ -1049,8 +1085,7 @@ static int mxuport_probe(struct usb_serial *serial,
>  {
>  	u16 productid = le16_to_cpu(serial->dev->descriptor.idProduct);
>  	const struct firmware *fw_p = NULL;
> -	u32 version;
> -	int local_ver;
> +	struct mxuport_fw_version version, local_ver;

Nit: I'd move this line above fw_p to maintain reverse xmas style of the
declarations.

>  	char buf[32];
>  	int err;

Johan

  reply	other threads:[~2026-07-21 14:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23  8:01 [PATCH v2 0/4] USB: serial: mxuport: add MUX50U support and updates Crescent Hsieh
2026-06-23  8:01 ` [PATCH v2 1/4] USB: serial: mxuport: clean up firmware version handling Crescent Hsieh
2026-07-21 14:34   ` Johan Hovold [this message]
2026-06-23  8:01 ` [PATCH v2 2/4] USB: serial: mxuport: add MUX50U-based device support Crescent Hsieh
2026-07-21 14:59   ` Johan Hovold
2026-06-23  8:01 ` [PATCH v2 3/4] USB: serial: mxuport: handle SEND_NEXT transmit flow control Crescent Hsieh
2026-07-21 15:51   ` Johan Hovold
2026-06-23  8:01 ` [PATCH v2 4/4] USB: serial: mxuport: support RS485 mode configuration Crescent Hsieh

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=al-DXpI52HuWBNwG@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=Epson.Chiang@moxa.com \
    --cc=FangpingFP.Cheng@moxa.com \
    --cc=crescentcy.hsieh@moxa.com \
    --cc=gregkh@linuxfoundation.org \
    --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