From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.171.202.116 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796297974; b=xdY/uqUS68L/Gi5jDfLLw4GVSzuXVOO9YxWRFw/u/J8d4NmJfOFiWXr3Yodv/EMfPX18 qywwLKCPdA2nDCX7IG9SxTFE4HJPX3dat7cmSS0BdVnhIsoz0ZjHWx/j9GSmDOeyVmZHm jwqwy/wV136HebMGPKD56rU1BOPACUrdU6yzBmZ3WINdqTj+p5SAojqtogOQr4o3XBGwc jZBZWfsNU1fPdx9lMoHbmZ+zkMtwykMYmAOC7Ri2Icjz+lwNxEQlbZNs4TEdpF5AhjjUq E4kmhoZnyK2/YjHONLyywgdzlppcsGfemNqkkqwH/PFr4IYHHlq4hBkNHrqBMGJ+UqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796297974; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:In-Reply-To:References:User-Agent:Date:Message-ID: MIME-Version:Content-Type:X-Last-TLS-Session-Version; bh=KB4+fr9AKdVg6FzSDAkov9xz15MN4wzlEcf4lRlqWOE=; b=2lXAhb55y2JOQSd9Tw2xgpR6ZnrQlem3qATNz3Le9FnuVg9WixuBfB53M4OkovrJzYBP 66la0hes55f1AV+cZsemHUSBjzuMDBwokBGjbrhlkLTK1F7HmQbyoazYMRmNCfjAgLVS8 ImJvP4cWTrnCNwMlqP+7TPwRJy7+mVmobq0Xtoxoi99PgyRvd9UOW6SHTOI7S/1lWs+bz Ejav7ZwseMJdeNY9mgkpuiF9mEuY9Y2tXktDbBbfX7BaWokVX1g/nhR1rbuKv7aQkjjph XKGINtqe4pA1CCkiw/uTeWtzuV+6If2M8eV6XnXL3zfwcppEAmlL2LrkVE1JI0jNlZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=u0j4pHAM; arc=none smtp.remote-ip=185.171.202.116 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 457B8606A682; Thu, 3 Dec 2026 11:39:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 457B8606A682 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=u0j4pHAM Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 4CBB2C0133E; Thu, 3 Dec 2026 11:39:43 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id CAB04604ED; Thu, 3 Dec 2026 11:39:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 4CD5911EA1A0B; Thu, 03 Dec 2026 12:39:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796297967; h=from:subject:date:message-id:to:cc:mime-version:content-type: in-reply-to:references; bh=KB4+fr9AKdVg6FzSDAkov9xz15MN4wzlEcf4lRlqWOE=; b=u0j4pHAMjkNdngtV75Mx6htl2QsbIMHkzuGGfw1Z/FAhgPCQtvK3xw5gVDG+MgOs5KlDLv /LCHmCF8I8ioKFgPGsHeyS64JA6EabBtPm/M8n6Ib556rAJhlDbs3V120daI/Qw5Cih+HG 4z7dZ3HEcOvE8zAkKnurbVCua+yUUSzLGUg24isfCwdV4Vb7HPm0x2qZ2s2j7uQxgFqoUY 8Wdm2V9GSq8FtdKc68jto+suDNAz8q8mJ9LUdZYDEFQiGJRZLL7Dh8hwGw1U1AlxRj9xqD 0X6Jell5SQT1W0UqBn3cK04cSglh3t+ZeRhOJNRjrVZVE1nKF8O7IrOvVG1kGw== From: Miquel Raynal To: Arina Kharlamova via B4 Relay Cc: Pali =?utf-8?Q?Roh=C3=A1r?= , Greg Kroah-Hartman , Jiri Slaby , Gregory CLEMENT , Wilson Ding , arina.kharlamova@mbzuai.ac.ae, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [PATCH v2] serial: mvebu-uart: do not leave a stale port behind when probe fails In-Reply-To: <20261203-v08b-v2-1-79564cfdbb46@mbzuai.ac.ae> (Arina Kharlamova via's message of "Thu, 03 Dec 2026 15:11:44 +0400") References: <20261203-v08b-v2-1-79564cfdbb46@mbzuai.ac.ae> User-Agent: mu4e 1.12.12; emacs 30.2 Date: Thu, 03 Dec 2026 12:39:23 +0100 Message-ID: <87a4mmioes.fsf@bootlin.com> X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain X-Last-TLS-Session-Version: TLSv1.3 On 03/12/2026 at 15:11:44 +04, Arina Kharlamova via B4 Relay wrote: > From: Arina Kharlamova > > mvebu_uart_probe() fills the static mvebu_uart_ports[] entry with the > devm mapping and the devm private data before it gets the clock and > the interrupts, and keeps them if uart_add_one_port() fails. On any of > these failures devres unmaps the registers and frees the private data, > but the static port keeps membase, mapbase and private_data. > > mvebu_uart_console_setup() only checks membase and mapbase. When > another port registers the console first, for example with > console=ttyMV1 and ttyMV1 still waiting for its clock, the setup > callback uses the stale port, accesses the unmapped registers and > dereferences the freed private data. > > Keep the mapping in a local variable, test is_ext through mvuart > instead of the port, and store membase, mapbase and private_data in > the port only after the last step that can fail before > uart_add_one_port(). Clear them again if uart_add_one_port() fails. > > Fixes: 30530791a7a0 ("serial: mvebu-uart: initial support for Armada-3700 serial port") > Signed-off-by: Arina Kharlamova > --- > The static port array keeps pointers into devm memory after a failed > or deferred probe. This patch moves the assignment of membase, mapbase > and private_data after the clock and the interrupts and clears them > when uart_add_one_port() fails. It is independent of my earlier clock > patch for this driver; both add the same ret variable, so the one > applied second needs git am -3. > > I noticed this while working on "serial: mvebu-uart: disable the clock > when probe fails": > https://lore.kernel.org/r/20261129-s2p-v08-v1-1-342b7170e692@mbzuai.ac.ae > The Sashiko review pointed at it. With the help of an AI coding > assistant (Claude); I reviewed the analysis and the fix. > Compile-tested only, not tested on hardware. > --- > Changes in v2: > - Set private_data after the clock and the interrupts too, and clear > membase, mapbase and private_data when uart_add_one_port() fails > (Sashiko review). > - Fixes: point at the commit that added the uart_add_one_port() path. > - Drop the Reviewed-by from Miquel Raynal, the patch changed. Not sure it changed enough to drop it. Reviewed-by: Miquel Raynal