Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3803556pxb; Mon, 4 Oct 2021 09:56:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiFW1Ai6X0RqaoaVt/MkDbdQzx6VaXqhivgpwBKO7PssJUlBh7qaaMibYOZdNgdXRP/pVA X-Received: by 2002:a17:90a:6a8f:: with SMTP id u15mr16370831pjj.212.1633366613775; Mon, 04 Oct 2021 09:56:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633366613; cv=none; d=google.com; s=arc-20160816; b=ez8bIq+DFgRhq33bWFVUG9iJ0DiR+0JDHybNSYNBBWBgDPeihsNNg318ihCkrlCkM0 +I/pqzk20gxoZMTKYQXLDLgN3l5UpjO5pOB7kbmzRDbmpvZgFr4gY1Vla6k8Xm5uoOMs iTo+8SOIhIEljkHJE5JTHU6ZS5pOfk3fkEqoU1cjBp6flTurW97u3T6VPesDOYTO9x7n f5W9Ta/q4mAnD2iF5bhzsHdMiPxxnxllkxgbDlegToSerOgDjV9AwCxMwdjxJGzU5TJi YUChUg7xJAoXKUB0J+EZJA27QMvY7s999pNxl3fwE+TUahRb+OgZcTkBu8W32dSDeFpK cC7g== 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=q1y4k6qKX55sSbfobjpE8XXr2A50sSBTHw5bDbNKQOw=; b=hb4uorjFvRRQKSD1x0C7xRbDz9aVXebVb07b0QiCBvaBU57SBJ8t1yV513trlGHCbG 81kPCAQcihv3Pi6RLiAqS7kjs1y5uBpkyroKq/V3mvc7hH/o1j1rhlpNFD76HqktsAZF 6dHVzWQ8LNaMxnJL1yNqA+BsTnWsp+o5CuH5hQEp7enXZuW5LzZSWT7TToFjGMyD9VdR vPQL2ATIDCm2e/K2uovuBPH8KT7RhNMWRD1Lgfs5AVsOZWCko4+Q7CKKQpZm8rOUa/WW 51KsxriWhbPnRVIDJ7A3+VVWlDqI0nPiaeGJw2+0J9AUUtJGGnfTAGCP2Es4cKc6Vdol 0dZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0HmoitXs; 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=pass (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 il8si23152548pjb.93.2021.10.04.09.56.39; Mon, 04 Oct 2021 09:56: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=@linuxfoundation.org header.s=korg header.b=0HmoitXs; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238145AbhJDNls (ORCPT + 99 others); Mon, 4 Oct 2021 09:41:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:51590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238283AbhJDNkN (ORCPT ); Mon, 4 Oct 2021 09:40:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 47AD361B46; Mon, 4 Oct 2021 13:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353493; bh=3a/p6USFOowNBjwbkRo1h4fNfmYZcvpMmQ1D6zouULs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0HmoitXsVluqBvuXeNkkj9zMEynKijGwXUbL2aV6lFhWyDmoMrNJN/xrzw3Ln0U2l j8CP0crP7v30yq+xUuNExzYJLysGMAM8B/yb1UaVfEjKRi9ZF3vpyloTmyav1s92KA +whz2P3nsCr3pmsSIC9QZQkTki66csDfFVUQnpgA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Samuel Iglesias Gonsalvez , Johan Hovold Subject: [PATCH 5.14 150/172] ipack: ipoctal: fix tty-registration error handling Date: Mon, 4 Oct 2021 14:53:20 +0200 Message-Id: <20211004125049.807143851@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@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: Johan Hovold commit cd20d59291d1790dc74248476e928f57fc455189 upstream. Registration of the ipoctal tty devices is unlikely to fail, but if it ever does, make sure not to deregister a never registered tty device (and dereference a NULL pointer) when the driver is later unbound. Fixes: 2afb41d9d30d ("Staging: ipack/devices/ipoctal: Check tty_register_device return value.") Cc: stable@vger.kernel.org # 3.7 Acked-by: Samuel Iglesias Gonsalvez Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20210917114622.5412-4-johan@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/ipack/devices/ipoctal.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/drivers/ipack/devices/ipoctal.c +++ b/drivers/ipack/devices/ipoctal.c @@ -33,6 +33,7 @@ struct ipoctal_channel { unsigned int pointer_read; unsigned int pointer_write; struct tty_port tty_port; + bool tty_registered; union scc2698_channel __iomem *regs; union scc2698_block __iomem *block_regs; unsigned int board_id; @@ -397,9 +398,11 @@ static int ipoctal_inst_slot(struct ipoc i, NULL, channel, NULL); if (IS_ERR(tty_dev)) { dev_err(&ipoctal->dev->dev, "Failed to register tty device.\n"); + tty_port_free_xmit_buf(&channel->tty_port); tty_port_destroy(&channel->tty_port); continue; } + channel->tty_registered = true; } /* @@ -699,6 +702,10 @@ static void __ipoctal_remove(struct ipoc for (i = 0; i < NR_CHANNELS; i++) { struct ipoctal_channel *channel = &ipoctal->channel[i]; + + if (!channel->tty_registered) + continue; + tty_unregister_device(ipoctal->tty_drv, i); tty_port_free_xmit_buf(&channel->tty_port); tty_port_destroy(&channel->tty_port);