public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
To: Jian Hui Lee <jianhui.lee@canonical.com>
Cc: andi.shyti@kernel.org, arnd@arndb.de, biju.das.jz@bp.renesas.com,
	conor+dt@kernel.org, devicetree@vger.kernel.org,
	fabrizio.castro.jz@renesas.com, geert+renesas@glider.be,
	gregkh@linuxfoundation.org, jonathan.cameron@huawei.com,
	kishon@kernel.org, krzk+dt@kernel.org,
	linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org,
	linux-renesas-soc@vger.kernel.org, magnus.damm@gmail.com,
	p.zabel@pengutronix.de, peda@axentia.se,
	prabhakar.mahadev-lad.rj@bp.renesas.com, robh@kernel.org,
	sebastian.reichel@collabora.com, tomm.merciai@gmail.com,
	ukleinek@kernel.org, vkoul@kernel.org,
	yoshihiro.shimoda.uh@renesas.com
Subject: Re: [PATCH v4 06/22] mux: Add driver for Renesas RZ/V2H USB VBUS_SEL mux
Date: Thu, 27 Nov 2025 10:07:23 +0100	[thread overview]
Message-ID: <aSgUpIGfpYXgH1-X@tom-desktop> (raw)
In-Reply-To: <20251127022841.743277-1-jianhui.lee@canonical.com>

Hi Jian,
Thanks for your comments!

On Thu, Nov 27, 2025 at 10:28:41AM +0800, Jian Hui Lee wrote:
> On Fri, Nov 21, 2025 at 04:11:55PM +0100, Tommaso Merciai wrote:
> > As per the RZ/V2H(P) HW manual, VBUSEN can be controlled by the VBUS_SEL
> > bit of the VBENCTL Control Register. This register is mapped in the
> > reset framework. The reset driver expose this register as mux-controller
> > and instantiates this driver. The consumer will use the mux API to
> > control the VBUS_SEL bit.
> > 
> > Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> > ---
> > v3->v4:
> >  - Removed mux_chip->dev.of_node not needed.
> > 
> > v2->v3:
> >  - Added mux_chip->dev.of_node = dev->of_node->child as the mux-controller
> >    is an internal node.
> >  - Fixed auxiliary_device_id name.
> >  - Get rdev using from platform_data.
> >  - Drop struct auxiliary_device adev from reset_rzv2h_usb2phy_adev
> >    as it is needed.
> >  - Drop to_reset_rzv2h_usb2phy_adev() as it is not needed.
> > 
> > v1->v2:
> >  - New patch
> > 
> >  drivers/mux/Kconfig                       | 10 +++
> >  drivers/mux/Makefile                      |  2 +
> >  drivers/mux/rzv2h-usb-vbus.c              | 97 +++++++++++++++++++++++
> >  include/linux/reset/reset_rzv2h_usb2phy.h | 11 +++
> >  4 files changed, 120 insertions(+)
> >  create mode 100644 drivers/mux/rzv2h-usb-vbus.c
> >  create mode 100644 include/linux/reset/reset_rzv2h_usb2phy.h
> > 
> > diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig
> > index c68132e38138..604f625544ed 100644
> > --- a/drivers/mux/Kconfig
> > +++ b/drivers/mux/Kconfig
> > @@ -59,4 +59,14 @@ config MUX_MMIO
> >  	  To compile the driver as a module, choose M here: the module will
> >  	  be called mux-mmio.
> >  
> > +config MUX_RZV2H_VBENCTL
> > +	tristate "Renesas RZ/V2H USB VBUS mux driver"
> > +	depends on RESET_RZV2H_USB2PHY || COMPILE_TEST
> > +	depends on OF
> > +	select REGMAP_MMIO
> > +	select AUXILIARY_BUS
> > +	default RESET_RZV2H_USB2PHY
> > +	help
> > +	  Support for VBUS mux implemented on Renesas RZ/V2H SoCs.
> > +
> >  endmenu
> > diff --git a/drivers/mux/Makefile b/drivers/mux/Makefile
> > index 6e9fa47daf56..9421660399af 100644
> > --- a/drivers/mux/Makefile
> > +++ b/drivers/mux/Makefile
> > @@ -8,9 +8,11 @@ mux-adg792a-objs		:= adg792a.o
> >  mux-adgs1408-objs		:= adgs1408.o
> >  mux-gpio-objs			:= gpio.o
> >  mux-mmio-objs			:= mmio.o
> > +mux-rzv2h-usb-vbus-objs		:= rzv2h-usb-vbus.o
> >  
> >  obj-$(CONFIG_MULTIPLEXER)	+= mux-core.o
> >  obj-$(CONFIG_MUX_ADG792A)	+= mux-adg792a.o
> >  obj-$(CONFIG_MUX_ADGS1408)	+= mux-adgs1408.o
> >  obj-$(CONFIG_MUX_GPIO)		+= mux-gpio.o
> >  obj-$(CONFIG_MUX_MMIO)		+= mux-mmio.o
> > +obj-$(CONFIG_MUX_RZV2H_VBENCTL)	+= mux-rzv2h-usb-vbus.o
> > diff --git a/drivers/mux/rzv2h-usb-vbus.c b/drivers/mux/rzv2h-usb-vbus.c
> > new file mode 100644
> > index 000000000000..9513bc8f35ff
> > --- /dev/null
> > +++ b/drivers/mux/rzv2h-usb-vbus.c
> > @@ -0,0 +1,97 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Renesas RZ/V2H(P) USB2 VBUS_SEL mux driver
> > + *
> > + * Copyright (C) 2025 Renesas Electronics Corp.
> > + */
> > +
> > +#include <linux/auxiliary_bus.h>
> > +#include <linux/bitops.h>
> > +#include <linux/err.h>
> > +#include <linux/module.h>
> > +#include <linux/mux/driver.h>
> > +#include <linux/of.h>
> > +#include <linux/property.h>
> > +#include <linux/regmap.h>
> > +#include <linux/reset/reset_rzv2h_usb2phy.h>
> > +
> > +#define RZV2H_VBENCTL		0xf0c
> > +
> > +struct mux_rzv2h_usb_vbus_priv {
> > +	struct regmap_field *field;
> > +};
> > +
> > +static int mux_rzv2h_usb_vbus_set(struct mux_control *mux, int state)
> > +{
> > +	struct mux_rzv2h_usb_vbus_priv *priv = mux_chip_priv(mux->chip);
> > +
> > +	return regmap_field_write(priv->field, state);
> > +}
> > +
> > +static const struct mux_control_ops mux_rzv2h_usb_vbus_ops = {
> > +	.set = mux_rzv2h_usb_vbus_set,
> > +};
> > +
> > +static const struct regmap_config rzv2h_usb_vbus_regconf = {
> > +	.reg_bits = 32,
> > +	.val_bits = 32,
> > +	.reg_stride = 4,
> > +	.max_register = RZV2H_VBENCTL,
> > +};
> > +
> > +static int mux_rzv2h_usb_vbus_probe(struct auxiliary_device *adev,
> > +				    const struct auxiliary_device_id *id)
> > +{
> > +	struct reset_rzv2h_usb2phy_adev *rdev = adev->dev.platform_data;
> > +	struct mux_rzv2h_usb_vbus_priv *priv;
> > +	struct device *dev = &adev->dev;
> > +	struct mux_chip *mux_chip;
> > +	struct regmap *regmap;
> > +	struct reg_field reg_field = {
> > +		.reg = RZV2H_VBENCTL,
> > +		.lsb = 0,
> > +		.msb = 0,
> > +	};
> > +	int ret;
> > +
> > +	regmap = devm_regmap_init_mmio(dev, rdev->base, &rzv2h_usb_vbus_regconf);
> > +	if (IS_ERR(regmap))
> > +		return PTR_ERR(regmap);
> > +
> > +	mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*priv));
> > +	if (IS_ERR(mux_chip))
> > +		return PTR_ERR(mux_chip);
> > +
> > +	priv = mux_chip_priv(mux_chip);
> > +
> > +	priv->field = devm_regmap_field_alloc(dev, regmap, reg_field);
> > +	if (IS_ERR(priv->field))
> > +		return PTR_ERR(priv->field);
> > +
> > +	mux_chip->ops = &mux_rzv2h_usb_vbus_ops;
> > +	mux_chip->mux[0].states = 2;
> > +	mux_chip->mux[0].idle_state = MUX_IDLE_AS_IS;
> > +
> > +	ret = devm_mux_chip_register(dev, mux_chip);
> > +	if (ret < 0)
> > +		return dev_err_probe(dev, ret, "Failed to register mux chip\n");
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct auxiliary_device_id mux_rzv2h_usb_vbus_ids[] = {
> > +	{ .name = "rzv2h_usb2phy_reset.vbus-sel-mux" },
> 
> hi Tommaso,
> this string causes buffer overflow, could you help to check on it?

I'll send v5 with:

	{ .name = "rzv2h_usb2phy_reset.vbenctl" },

in v5.
Thank you!


Kind Regards,
Tommaso

> 
> [   15.349036] strlen: detected buffer overflow: 33 byte read of buffer size 32
> [   15.349083] WARNING: CPU: 0 PID: 518 at lib/string_helpers.c:1035 __fortify_report+0x64/0xc8
> [   15.349110] Modules linked in: mux_rzv2h_usb_vbus(+) rcar_canfd(+) mtd sm4_ce(-) can_dev rz_dmac(+) pwm_rzg2l_gpt binfmt_misc dm_multipath efi_pstore nfnetlink ip_tables x_tables autofs4 btrfs blake2b_generic raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor xor_neon raid6_pq raid1 raid0 linear rtc_isl1208 micrel phy_package mmc_block raa215300 rpmb_core dwmac_renesas_gbeth spi_rpc_if pcs_rzn1_miic stmmac_platform stmmac polyval_ce renesas_sdhi_internal_dmac renesas_usbhs ghash_ce panfrost udc_core pcs_xpcs renesas_sdhi_core reset_rzv2h_usb2phy gpu_sched tmio_mmc_core xhci_rcar_hcd ehci_platform sm4 phy_rzg3e_usb3 phy_rcar_gen3_usb2 rzv2m_usb3drd xhci_plat_hcd ohci_platform renesas_rpc_if i2c_riic gpio_regulator gpio_keys fixed aes_neon_bs aes_neon_blk aes_ce_blk aes_ce_cipher
> [   15.349359] CPU: 0 UID: 0 PID: 518 Comm: (udev-worker) Not tainted 6.18.0-5.5 #3 PREEMPT(voluntary)
> [   15.349371] Hardware name: Renesas SMARC EVK version 2 based on r9a09g047e57 (DT)
> [   15.349380] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
> [   15.349390] pc : __fortify_report+0x64/0xc8
> [   15.349400] lr : __fortify_report+0x64/0xc8
> [   15.349408] sp : ffff8000854fb830
> [   15.349413] x29: ffff8000854fb830 x28: ffff80007c7a41d8 x27: ffff80007c7a4300
> [   15.349430] x26: ffff800083c4d780 x25: 0000000000000000 x24: ffff0000c5de9de8
> [   15.349446] x23: ffff800081d23b68 x22: ffff0000c004b200 x21: ffff0000ca6dd080
> [   15.349462] x20: 0000000000000020 x19: ffff80007c7a6140 x18: ffff800084b870a8
> [   15.349477] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000
> [   15.349492] x14: 0000000000000000 x13: 323320657a697320 x12: 7265666675622066
> [   15.349507] x11: 0000000000000000 x10: 0000000000000000 x9 : ffff800080208f0c
> [   15.349522] x8 : 0000000000000000 x7 : 0000000000000000 x6 : 0000000000000000
> [   15.349536] x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000
> [   15.349550] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000000
> [   15.349565] Call trace:
> [   15.349572]  __fortify_report+0x64/0xc8 (P)
> [   15.349583]  __fortify_panic+0x14/0x18
> [   15.349595]  auxiliary_match_id+0xf8/0x110
> [   15.349608]  auxiliary_match+0x28/0x60
> [   15.349617]  __driver_attach+0x34/0x2a8
> [   15.349629]  bus_for_each_dev+0x88/0x110
> [   15.349639]  driver_attach+0x30/0x60
> [   15.349649]  bus_add_driver+0x178/0x2d8
> [   15.349658]  driver_register+0x74/0x178
> [   15.349668]  __auxiliary_driver_register+0x7c/0x150
> [   15.349677]  mux_rzv2h_usb_vbus_driver_init+0x34/0xfd0 [mux_rzv2h_usb_vbus]
> 
> > +	{ /* sentinel */ }
> > +};
> > +MODULE_DEVICE_TABLE(auxiliary, mux_rzv2h_usb_vbus_ids);
> > +
> > +static struct auxiliary_driver mux_rzv2h_usb_vbus_driver = {
> > +	.name		= "vbus-sel-mux",
> > +	.probe		= mux_rzv2h_usb_vbus_probe,
> > +	.id_table	= mux_rzv2h_usb_vbus_ids,
> > +};
> > +module_auxiliary_driver(mux_rzv2h_usb_vbus_driver);
> > +
> > +MODULE_DESCRIPTION("RZ/V2H USB VBUS_SEL mux driver");
> > +MODULE_AUTHOR("Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>");
> > +MODULE_LICENSE("GPL");
> > diff --git a/include/linux/reset/reset_rzv2h_usb2phy.h b/include/linux/reset/reset_rzv2h_usb2phy.h
> > new file mode 100644
> > index 000000000000..06247080a66c
> > --- /dev/null
> > +++ b/include/linux/reset/reset_rzv2h_usb2phy.h
> > @@ -0,0 +1,11 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +#ifndef _RESET_RZV2H_USB2PHY_H
> > +#define _RESET_RZV2H_USB2PHY_H
> > +
> > +#include <linux/auxiliary_bus.h>
> > +
> > +struct reset_rzv2h_usb2phy_adev {
> > +	void __iomem *base;
> > +};
> > +
> > +#endif
> > -- 
> > 2.43.0
> > 
> > 
> > -- 
> > linux-phy mailing list
> > linux-phy@lists.infradead.org
> > https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2025-11-27  9:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21 15:11 [PATCH v4 00/22] Add USB2.0 support for RZ/G3E Tommaso Merciai
2025-11-21 15:11 ` [PATCH v4 01/22] dt-bindings: mux: Remove nodename pattern constraints Tommaso Merciai
2025-11-21 18:24   ` Conor Dooley
2025-11-24  8:57     ` Tommaso Merciai
2025-11-21 15:11 ` [PATCH v4 02/22] phy: renesas: rcar-gen3-usb2: Use devm_pm_runtime_enable() Tommaso Merciai
2025-11-21 15:11 ` [PATCH v4 03/22] phy: renesas: rcar-gen3-usb2: Factor out VBUS control logic Tommaso Merciai
2025-11-21 15:11 ` [PATCH v4 04/22] reset: rzv2h-usb2phy: Keep PHY clock enabled for entire device lifetime Tommaso Merciai
2025-11-21 15:11 ` [PATCH v4 05/22] dt-bindings: reset: renesas,rzv2h-usb2phy: Add '#mux-state-cells' property Tommaso Merciai
2025-11-21 15:11 ` [PATCH v4 06/22] mux: Add driver for Renesas RZ/V2H USB VBUS_SEL mux Tommaso Merciai
2025-11-27  2:28   ` Jian Hui Lee
2025-11-27  9:07     ` Tommaso Merciai [this message]
2025-11-21 15:11 ` [PATCH v4 07/22] reset: rzv2h-usb2phy: Add support for VBUS mux controller registration Tommaso Merciai
2025-11-21 15:11 ` [PATCH v4 08/22] dt-bindings: phy: renesas,usb2-phy: Document USB VBUS regulator Tommaso Merciai
2025-11-21 15:11 ` [PATCH v4 09/22] dt-bindings: phy: renesas,usb2-phy: Document mux-states property Tommaso Merciai
2025-11-21 15:11 ` [PATCH v4 10/22] phy: renesas: rcar-gen3-usb2: Add regulator for OTG VBUS control Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 11/22] phy: renesas: rcar-gen3-usb2: Use mux-state for phyrst management Tommaso Merciai
2025-11-25 14:10   ` Geert Uytterhoeven
2025-11-25 15:57     ` Tommaso Merciai
2025-11-26  7:43       ` Geert Uytterhoeven
2025-11-21 15:12 ` [PATCH v4 12/22] dt-bindings: usb: renesas,usbhs: Add RZ/G3E SoC support Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 13/22] dt-bindings: phy: renesas,usb2-phy: Document RZ/G3E SoC Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 14/22] dt-bindings: reset: Document RZ/G3E USB2PHY reset Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 15/22] arm64: dts: renesas: r9a09g057: Add USB2.0 VBUS_SEL mux-controller support Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 16/22] arm64: dts: renesas: r9a09g056: " Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 17/22] arm64: dts: renesas: r9a09g056: Add USB2.0 PHY VBUS internal regulator node Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 18/22] arm64: dts: renesas: r9a09g056n48-rzv2n-evk: Enable USB2 PHY0 VBUS support Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 19/22] arm64: dts: renesas: r9a09g057: Add USB2.0 PHY VBUS internal regulator node Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 20/22] arm64: dts: renesas: r9a09g057h44-rzv2h-evk: Enable USB2 PHY0 VBUS support Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 21/22] arm64: dts: renesas: r9a09g047: Add USB2.0 support Tommaso Merciai
2025-11-21 15:12 ` [PATCH v4 22/22] arm64: dts: renesas: r9a09g047e57-smarc: Enable " Tommaso Merciai

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=aSgUpIGfpYXgH1-X@tom-desktop \
    --to=tommaso.merciai.xr@bp.renesas.com \
    --cc=andi.shyti@kernel.org \
    --cc=arnd@arndb.de \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=jianhui.lee@canonical.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=kishon@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=peda@axentia.se \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=robh@kernel.org \
    --cc=sebastian.reichel@collabora.com \
    --cc=tomm.merciai@gmail.com \
    --cc=ukleinek@kernel.org \
    --cc=vkoul@kernel.org \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /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