Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3701028pxk; Tue, 29 Sep 2020 04:11:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyau9mbnVv/fjiIOucjmYu06ZaIO6i+7MbrXm5myRaPz+IwS34uHXazZJ1giz7ktjsKjpih X-Received: by 2002:a17:906:5299:: with SMTP id c25mr3231873ejm.508.1601377913982; Tue, 29 Sep 2020 04:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601377913; cv=none; d=google.com; s=arc-20160816; b=EKL95b8lyOQ46d1ZXtBgtek2jELHlr0tY3Wt6WWP2aoKtbgzWX+Gtw5spGuoXpRA5y aHAAvNjDXT5kDFqNiJa/1WwWgk1f9x51nWva7opQ+605gO9ANxCEhO4DqHNtbq925ZeD Txn1gfI99TFFaYB8G9eaR36uFSlVOv2H4Xxy/d48g2lyjHv9xBbw+vBAk39Rh7JaQL6s /4zFemFaUr0HsC5Ipn/vgvhyLnO8dM9LrosXxymh3lSoP1rgw+5Zy+r9twpHOlSZX4Cx G6ULrx95tej3UcSLupcAsNofWp+qLAAbiz0Ndq623CL8+y3LW/ZLcJxVxi8az6pPGGYu kRWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sR4xUkiys9gMOb53MWmHO0Pu/VZjArWeuVhz1RiAU8s=; b=qiYw7Ql8It4LcE35FPEqWMZ9dwNRgfEn7Ojp6myma/IooqFCJE2ZP535DRJqAyQdjC 6qnVRt2BwKSImV8pqy6xi6APwFE63KVG86qN181+EyKE0rGZw/LrcOQDDo/07IIf3f/X b8hgldtC9p3WCoHGVNCWRJmyCUPqL5nhyoCFf6cN4dkcjpu5LYl6puH1J+5QA4zoc3eW sdhCN4f6dFTqMQ06OkAeRN0VdCtncx7j39ipHWJaKovJXDGIeUA3jVYuy7JLyBrnEK73 y3D9BntIjyHQ7OktaavLW951OCZzgW8weqjSjpbeBs/qWC8Ps9xBhIoNKmQrMQONNWG2 BtMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PicKAKmA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l8si2411035edr.396.2020.09.29.04.11.30; Tue, 29 Sep 2020 04:11:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PicKAKmA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728911AbgI2LHW (ORCPT + 99 others); Tue, 29 Sep 2020 07:07:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:45048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728879AbgI2LHD (ORCPT ); Tue, 29 Sep 2020 07:07:03 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB52021D7D; Tue, 29 Sep 2020 11:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377622; bh=dohjpOr0OAQhlF+dnzRhyyW82Oenaegp3P3XhmWxpvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PicKAKmA1UCzWxAev4qDLIPNMs5ctS96jff6w2UB15oXpCCG5L22xytYi5D5RDM16 l78aAcoIxhc7z0QkpqOgkaX6Ve8qzt31YyMz9y5h2UqdOWQxt5qFMW9SGnCunq+3S3 aboyvhFf26UmP/4TgQOTOWCnCTGmoJfzsopTNU6Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Andy Shevchenko , "Nobuhiro Iwamatsu (CIP)" Subject: [PATCH 4.9 013/121] serial: 8250: Avoid error message on reprobe Date: Tue, 29 Sep 2020 12:59:17 +0200 Message-Id: <20200929105930.837077444@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105930.172747117@linuxfoundation.org> References: <20200929105930.172747117@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner commit e0a851fe6b9b619527bd928aa93caaddd003f70c upstream. If the call to uart_add_one_port() in serial8250_register_8250_port() fails, a half-initialized entry in the serial_8250ports[] array is left behind. A subsequent reprobe of the same serial port causes that entry to be reused. Because uart->port.dev is set, uart_remove_one_port() is called for the half-initialized entry and bails out with an error message: bcm2835-aux-uart 3f215040.serial: Removing wrong port: (null) != (ptrval) The same happens on failure of mctrl_gpio_init() since commit 4a96895f74c9 ("tty/serial/8250: use mctrl_gpio helpers"). Fix by zeroing the uart->port.dev pointer in the probe error path. The bug was introduced in v2.6.10 by historical commit befff6f5bf5f ("[SERIAL] Add new port registration/unregistration functions."): https://git.kernel.org/tglx/history/c/befff6f5bf5f The commit added an unconditional call to uart_remove_one_port() in serial8250_register_port(). In v3.7, commit 835d844d1a28 ("8250_pnp: do pnp probe before legacy probe") made that call conditional on uart->port.dev which allows me to fix the issue by zeroing that pointer in the error path. Thus, the present commit will fix the problem as far back as v3.7 whereas still older versions need to also cherry-pick 835d844d1a28. Fixes: 835d844d1a28 ("8250_pnp: do pnp probe before legacy probe") Signed-off-by: Lukas Wunner Cc: stable@vger.kernel.org # v2.6.10 Cc: stable@vger.kernel.org # v2.6.10: 835d844d1a28: 8250_pnp: do pnp probe before legacy Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/b4a072013ee1a1d13ee06b4325afb19bda57ca1b.1589285873.git.lukas@wunner.de [iwamatsu: Backported to 4.4, 4.9: adjust context] Signed-off-by: Nobuhiro Iwamatsu (CIP) Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -1046,8 +1046,10 @@ int serial8250_register_8250_port(struct ret = uart_add_one_port(&serial8250_reg, &uart->port); - if (ret == 0) - ret = uart->port.line; + if (ret) + goto err; + + ret = uart->port.line; } else { dev_info(uart->port.dev, "skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n", @@ -1061,6 +1063,11 @@ int serial8250_register_8250_port(struct mutex_unlock(&serial_mutex); return ret; + +err: + uart->port.dev = NULL; + mutex_unlock(&serial_mutex); + return ret; } EXPORT_SYMBOL(serial8250_register_8250_port);