From patchwork Wed Feb 1 19:57:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian King X-Patchwork-Id: 649948 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF2ABC63797 for ; Wed, 1 Feb 2023 19:58:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232112AbjBAT6K (ORCPT ); Wed, 1 Feb 2023 14:58:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232166AbjBAT6I (ORCPT ); Wed, 1 Feb 2023 14:58:08 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DC01C667 for ; Wed, 1 Feb 2023 11:58:02 -0800 (PST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 311JqZSj026115; Wed, 1 Feb 2023 19:57:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=9szCe/pMSxH3ejAhsLxrEZP38yMrVIthoS8DpxwfO28=; b=mr7GaujL2mgKP+QDHIHqUkMxfYb4qN1B9dPRdn+o7QMyE3GKATSZSwYqPFC2Cr5ZoEaW EfCxtfiOp6BaobgRmMSJOUgiDjliUa9GEBjSWs4p2gnLue0YS47nZdT4rzh7Sz/T30fV kv0I4+UAKWCL+8G6EvI7ViWzB4ci+ezi6jaEICLLP+7H7mzZaC+V6lCew5V/koQ2yTPo 6MJ0VazPTGRFa5xw3J4pKbGZsPdgFKPyhYMF5I2/F0WgZZl46RUvO92Wz+Zq2b27orhC uDMFFgC40lEpbcz9pVL/phVNYaGrdKWaiOy2CFNH3jrW9r6O2t5WX4+GisTY5+EK07lM cw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfxmf82g1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:56 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 311JqtJi026600; Wed, 1 Feb 2023 19:57:56 GMT Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfxmf82fh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:56 +0000 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 311HTK4N012318; Wed, 1 Feb 2023 19:57:55 GMT Received: from smtprelay03.wdc07v.mail.ibm.com ([9.208.129.113]) by ppma05wdc.us.ibm.com (PPS) with ESMTPS id 3ncvvdqh9d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:55 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay03.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 311Jvsnf12845654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Feb 2023 19:57:54 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DCE0458057; Wed, 1 Feb 2023 19:57:53 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 694F258058; Wed, 1 Feb 2023 19:57:53 +0000 (GMT) Received: from li-6bf4d4cc-31f5-11b2-a85c-838e9310af65.ibm.com.com (unknown [9.211.132.88]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Feb 2023 19:57:53 +0000 (GMT) From: Brian King To: gregkh@linuxfoundation.org Cc: linuxppc-dev@lists.ozlabs.org, brking@pobox.com, mmc@linux.vnet.ibm.com, linux-serial@vger.kernel.org, Brian King Subject: [PATCH 1/6] hvcs: Fix hvcs port reference counting Date: Wed, 1 Feb 2023 13:57:38 -0600 Message-Id: <20230201195743.303163-2-brking@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201195743.303163-1-brking@linux.vnet.ibm.com> References: <20230201195743.303163-1-brking@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: v7uswBHvveXnc8KMdBkiaUvXHhQLuLan X-Proofpoint-ORIG-GUID: 7-R4uACNH45QXaY0ZnaCzOPL1wJyXXKW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-01_04,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 suspectscore=0 impostorscore=0 mlxscore=0 phishscore=0 clxscore=1015 priorityscore=1501 adultscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302010166 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The hvcs driver only ever gets two references to the port. One at initialization time, and one at install time. Remove the code that was trying to do multiple port puts for each open, which would result in more puts than gets. Signed-off-by: Brian King --- drivers/tty/hvc/hvcs.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c index 4ba24963685e..faf5ccfc561e 100644 --- a/drivers/tty/hvc/hvcs.c +++ b/drivers/tty/hvc/hvcs.c @@ -1215,12 +1215,9 @@ static void hvcs_hangup(struct tty_struct * tty) { struct hvcs_struct *hvcsd = tty->driver_data; unsigned long flags; - int temp_open_count; int irq; spin_lock_irqsave(&hvcsd->lock, flags); - /* Preserve this so that we know how many kref refs to put */ - temp_open_count = hvcsd->port.count; /* * Don't kref put inside the spinlock because the destruction @@ -1247,21 +1244,6 @@ static void hvcs_hangup(struct tty_struct * tty) spin_unlock_irqrestore(&hvcsd->lock, flags); free_irq(irq, hvcsd); - - /* - * We need to kref_put() for every open_count we have since the - * tty_hangup() function doesn't invoke a close per open connection on a - * non-console device. - */ - while(temp_open_count) { - --temp_open_count; - /* - * The final put will trigger destruction of the hvcs_struct. - * NOTE: If this hangup was signaled from user space then the - * final put will never happen. - */ - tty_port_put(&hvcsd->port); - } } /* From patchwork Wed Feb 1 19:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian King X-Patchwork-Id: 649601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EC3BC636D7 for ; Wed, 1 Feb 2023 19:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232147AbjBAT6L (ORCPT ); Wed, 1 Feb 2023 14:58:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232161AbjBAT6I (ORCPT ); Wed, 1 Feb 2023 14:58:08 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECF04BB8D for ; Wed, 1 Feb 2023 11:58:01 -0800 (PST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 311JQ7ri007833; Wed, 1 Feb 2023 19:57:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=2xwKp84M79wmucUQK2UjfTEtoLiOx5WCvSxnoWSN6LM=; b=IIhOTyYdtWGO1xpYDAlsWDi/TEcsbwkCbviGIPPkQtiGrz5ibeX9P1BEbdtW6C46Lhha CN9Dwgd7WbcCBnpJmi0s3p0/PrR37/rA0jv96AlT2TANS6nbLDEaeidFS4pEs6zbgxom YwIGoQ2stgik4tpOyUJogtO8L95GyKkVfy7IuiyWAk4/N7pbPw7+BQGsiRItFUuZRF9k FQmRtZG+VSxBhciRukwfFrscmCTPaPFy4J6sgKL3YixjwqXHNhKdZexsku4Qv1A5jt1G QZSs48Z54jyBS+RP5+YfEzwdDsfure5SGv8EhhJpIDDpj/fevC14URIHFvOpDWRM1ofd lg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfx7tgpgd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:57 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 311JtglL006572; Wed, 1 Feb 2023 19:57:57 GMT Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfx7tgpg6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:57 +0000 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 311IlA1p006449; Wed, 1 Feb 2023 19:57:56 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([9.208.129.114]) by ppma01dal.us.ibm.com (PPS) with ESMTPS id 3ncvtmna1y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:56 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 311JvsK821627436 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Feb 2023 19:57:54 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 881F658057; Wed, 1 Feb 2023 19:57:54 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A3A158058; Wed, 1 Feb 2023 19:57:54 +0000 (GMT) Received: from li-6bf4d4cc-31f5-11b2-a85c-838e9310af65.ibm.com.com (unknown [9.211.132.88]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Feb 2023 19:57:53 +0000 (GMT) From: Brian King To: gregkh@linuxfoundation.org Cc: linuxppc-dev@lists.ozlabs.org, brking@pobox.com, mmc@linux.vnet.ibm.com, linux-serial@vger.kernel.org, Brian King Subject: [PATCH 2/6] hvcs: Remove sysfs file prior to vio unregister Date: Wed, 1 Feb 2023 13:57:39 -0600 Message-Id: <20230201195743.303163-3-brking@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201195743.303163-1-brking@linux.vnet.ibm.com> References: <20230201195743.303163-1-brking@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: dNNU49SsiWquxJ8rv9K1Ik9QTN6OvYiB X-Proofpoint-ORIG-GUID: QktLyNIGDxT7QblnIurXriRfLJkSxlU6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-01_04,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 bulkscore=0 mlxscore=0 clxscore=1015 phishscore=0 malwarescore=0 priorityscore=1501 adultscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302010166 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org This moves the removal of the rescan sysfs attribute to occur before the call to unregister the vio to ensure the removal does not fail due to the vio driver already being freed. Signed-off-by: Brian King --- drivers/tty/hvc/hvcs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c index faf5ccfc561e..9131dcb2e8d8 100644 --- a/drivers/tty/hvc/hvcs.c +++ b/drivers/tty/hvc/hvcs.c @@ -1519,6 +1519,8 @@ static int __init hvcs_module_init(void) static void __exit hvcs_module_exit(void) { + driver_remove_file(&hvcs_vio_driver.driver, &driver_attr_rescan); + /* * This driver receives hvcs_remove callbacks for each device upon * module removal. @@ -1538,8 +1540,6 @@ static void __exit hvcs_module_exit(void) hvcs_pi_buff = NULL; spin_unlock(&hvcs_pi_lock); - driver_remove_file(&hvcs_vio_driver.driver, &driver_attr_rescan); - tty_unregister_driver(hvcs_tty_driver); hvcs_free_index_list(); From patchwork Wed Feb 1 19:57:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian King X-Patchwork-Id: 649602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 419AEC636D4 for ; Wed, 1 Feb 2023 19:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232166AbjBAT6L (ORCPT ); Wed, 1 Feb 2023 14:58:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232147AbjBAT6I (ORCPT ); Wed, 1 Feb 2023 14:58:08 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA74C64D for ; Wed, 1 Feb 2023 11:58:02 -0800 (PST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 311JnfFp020667; Wed, 1 Feb 2023 19:57:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=QpwMgr23nIiMkJ3ihnsLIr7pw0uxT05vUxhNww44wHs=; b=rvxLDnU7X32HfrFeQAvhSniw52NKytlo7hRlotPb8SlmNxD7UfwnJuqUocSKNAUZBW6u Nlw1Tz/+ADzhgJorVbjycE838g8hKZIuGDbbLwBsLrbt8vSqaQlxXAamg84B5DdDXgT5 x13SCm9QsqcPWvWq3KJVBBbimQqaPI0V+mYtov5ocLqE/WcEKE9jc0ErsvkCpfjjDjmv OoM5WsPYNHpczJTHHCC//oOPYaQ8jspxJPiXVT6AS4J6alCJqCWIXcgGfwtr/4/bgfAg iwiPO7+iEO76qmfPG6h2xGqSO4Cds0oI20f8xvWCAREnA8RxGH/fGX5Zr24+qPFpryjF zw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfxk485vq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:58 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 311JoD7Z022221; Wed, 1 Feb 2023 19:57:57 GMT Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfxk485va-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:57 +0000 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 311H8Cpb005396; Wed, 1 Feb 2023 19:57:56 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([9.208.129.117]) by ppma02wdc.us.ibm.com (PPS) with ESMTPS id 3ncvv1yh6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:56 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 311Jvtgx30802344 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Feb 2023 19:57:55 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D8ED58062; Wed, 1 Feb 2023 19:57:55 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A26AA58058; Wed, 1 Feb 2023 19:57:54 +0000 (GMT) Received: from li-6bf4d4cc-31f5-11b2-a85c-838e9310af65.ibm.com.com (unknown [9.211.132.88]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Feb 2023 19:57:54 +0000 (GMT) From: Brian King To: gregkh@linuxfoundation.org Cc: linuxppc-dev@lists.ozlabs.org, brking@pobox.com, mmc@linux.vnet.ibm.com, linux-serial@vger.kernel.org, Brian King Subject: [PATCH 3/6] hvcs: Remove sysfs group earlier Date: Wed, 1 Feb 2023 13:57:40 -0600 Message-Id: <20230201195743.303163-4-brking@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201195743.303163-1-brking@linux.vnet.ibm.com> References: <20230201195743.303163-1-brking@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: NecJQWBA0ZVN9TDz5nKQwXx-g5bQQrNl X-Proofpoint-ORIG-GUID: K8YR5HZg4fKE0J7NACAwbyO0s7EWgDGu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-01_04,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 malwarescore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302010166 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Cleanup the sysfs group earlier in remove. This eliminates errors coming from kernfs when attempting to remove a console device that is in use. Signed-off-by: Brian King --- drivers/tty/hvc/hvcs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c index 9131dcb2e8d8..9c5887d0c882 100644 --- a/drivers/tty/hvc/hvcs.c +++ b/drivers/tty/hvc/hvcs.c @@ -688,8 +688,6 @@ static void hvcs_destruct_port(struct tty_port *p) spin_unlock_irqrestore(&hvcsd->lock, flags); spin_unlock(&hvcs_structs_lock); - sysfs_remove_group(&vdev->dev.kobj, &hvcs_attr_group); - kfree(hvcsd); } @@ -814,6 +812,8 @@ static void hvcs_remove(struct vio_dev *dev) */ tty_port_put(&hvcsd->port); + sysfs_remove_group(&dev->dev.kobj, &hvcs_attr_group); + /* * The hangup is a scheduled function which will auto chain call * hvcs_hangup. The tty should always be valid at this time unless a From patchwork Wed Feb 1 19:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian King X-Patchwork-Id: 649947 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F374AC6379F for ; Wed, 1 Feb 2023 19:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232161AbjBAT6M (ORCPT ); Wed, 1 Feb 2023 14:58:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232202AbjBAT6I (ORCPT ); Wed, 1 Feb 2023 14:58:08 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70DB365B5 for ; Wed, 1 Feb 2023 11:58:02 -0800 (PST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 311JEv9T012747; Wed, 1 Feb 2023 19:57:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=gvimzOD4zncG4wSWh4kzyGq5ct7BpBxFgeaUAoZVERk=; b=TNJwUK/717Bwz0VCovfQkJM3j2vnYAnZb2U4OD3dyy83fuLETZWBqrGCOIHQPK4WRZK9 BgwHcj4Hss1N+ItS1UiapVcst5S6V6MtaUbdA2Qo7rE1S1rQOI7MAnNT/NnhmNZ8BwIW ReQVCKLklOGghwMRHe/KKXvokSN1Ld/MnEzwD7Bkbu/4Nv7uorjVgT3lTzIUaz1FpNoO 1ysh/M1cPVgbpg9HxhfimPUMvcTCwU4P/b7RiYfPGf0Zs+kPeYMU8/V0GPZ0AXNcfm7D qkss988tufGt8AJfjs1/+VTXtjc2nFV3DSLnqwBkaln0Z7YmkTcJUH1kBqtMRnVJNTkt qA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfwt41hg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:58 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 311JUM8V026709; Wed, 1 Feb 2023 19:57:58 GMT Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfwt41hg5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:58 +0000 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 311Ig7CL025825; Wed, 1 Feb 2023 19:57:57 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([9.208.129.117]) by ppma03dal.us.ibm.com (PPS) with ESMTPS id 3ncvtrwcsv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:57 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 311JvtRx7406302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Feb 2023 19:57:56 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3AF158061; Wed, 1 Feb 2023 19:57:55 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4620C58058; Wed, 1 Feb 2023 19:57:55 +0000 (GMT) Received: from li-6bf4d4cc-31f5-11b2-a85c-838e9310af65.ibm.com.com (unknown [9.211.132.88]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Feb 2023 19:57:55 +0000 (GMT) From: Brian King To: gregkh@linuxfoundation.org Cc: linuxppc-dev@lists.ozlabs.org, brking@pobox.com, mmc@linux.vnet.ibm.com, linux-serial@vger.kernel.org, Brian King Subject: [PATCH 4/6] hvcs: Get reference to tty in remove Date: Wed, 1 Feb 2023 13:57:41 -0600 Message-Id: <20230201195743.303163-5-brking@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201195743.303163-1-brking@linux.vnet.ibm.com> References: <20230201195743.303163-1-brking@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: K45NNftGJQWQxQgMi7zy8fIRff-m_UNq X-Proofpoint-GUID: 3F4KJerzXPIl-QegXL_yRChXZ2IzowtR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-01_04,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 phishscore=0 spamscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 suspectscore=0 impostorscore=0 clxscore=1015 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302010166 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Grab a reference to the tty when removing the hvcs to ensure it does not get freed unexpectedly. Signed-off-by: Brian King --- drivers/tty/hvc/hvcs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c index 9c5887d0c882..b28ddfc46e42 100644 --- a/drivers/tty/hvc/hvcs.c +++ b/drivers/tty/hvc/hvcs.c @@ -802,7 +802,7 @@ static void hvcs_remove(struct vio_dev *dev) spin_lock_irqsave(&hvcsd->lock, flags); - tty = hvcsd->port.tty; + tty = tty_port_tty_get(&hvcsd->port); spin_unlock_irqrestore(&hvcsd->lock, flags); @@ -819,8 +819,10 @@ static void hvcs_remove(struct vio_dev *dev) * hvcs_hangup. The tty should always be valid at this time unless a * simultaneous tty close already cleaned up the hvcs_struct. */ - if (tty) + if (tty) { tty_hangup(tty); + tty_kref_put(tty); + } printk(KERN_INFO "HVCS: vty-server@%X removed from the" " vio bus.\n", dev->unit_address); From patchwork Wed Feb 1 19:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian King X-Patchwork-Id: 649603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 429E2C636D7 for ; Wed, 1 Feb 2023 19:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232249AbjBAT6J (ORCPT ); Wed, 1 Feb 2023 14:58:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232112AbjBAT6I (ORCPT ); Wed, 1 Feb 2023 14:58:08 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5FD1C67B for ; Wed, 1 Feb 2023 11:58:02 -0800 (PST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 311JneDq020657; Wed, 1 Feb 2023 19:57:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=D3e0Ny4sWs3TLgoEO4MTBtcZqFtYmX6LCVazB3HfqYY=; b=JUHBXKLMpaeOzhUbAhSu9M7YxKhoE8c/bv4b5lzbVpjgyRTTOOz1bzskKRg/tVu8D0cV f8sH0XTkeZ217RtJbZnBUOHbgym360G4m5Rypv+oz7mEuqz3VJ0n1VcfTio4sNSdkhkH 0fTA1I8UVywfc2xB9VT13M6WhaqfI8A5kY9AadlyBxaGSwu3YPtHOecMLhNzsDkHq1zY ABhsOsZ10FrNREVFRF7IGTxPkFne4zM2X6OR+VYCy/Fpv6ISeCU/zNVx5bO7ENRdU9Vy Etmz0z3xd1dfNQ/yqPgDN0cG9dISe+Oq6dJN96phyUcJnJRUUQ/wKVkLF97LoieUESrV dA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfxk485w5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:59 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 311JnfWJ020674; Wed, 1 Feb 2023 19:57:59 GMT Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfxk485vr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:59 +0000 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 311HBYue026845; Wed, 1 Feb 2023 19:57:57 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([9.208.129.118]) by ppma01wdc.us.ibm.com (PPS) with ESMTPS id 3ncvtn7h9q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:57 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 311JvujW62193998 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Feb 2023 19:57:56 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 66D6358059; Wed, 1 Feb 2023 19:57:56 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE03258058; Wed, 1 Feb 2023 19:57:55 +0000 (GMT) Received: from li-6bf4d4cc-31f5-11b2-a85c-838e9310af65.ibm.com.com (unknown [9.211.132.88]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Feb 2023 19:57:55 +0000 (GMT) From: Brian King To: gregkh@linuxfoundation.org Cc: linuxppc-dev@lists.ozlabs.org, brking@pobox.com, mmc@linux.vnet.ibm.com, linux-serial@vger.kernel.org, Brian King Subject: [PATCH 5/6] hvcs: Use vhangup in hotplug remove Date: Wed, 1 Feb 2023 13:57:42 -0600 Message-Id: <20230201195743.303163-6-brking@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201195743.303163-1-brking@linux.vnet.ibm.com> References: <20230201195743.303163-1-brking@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: tZBc_dvEd96jI3_wfswrTtv241mUG8t2 X-Proofpoint-ORIG-GUID: WRzwRzlc8IU-vvgIPyDIJOB5E1i-Yhic X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-01_04,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 malwarescore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302010166 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org When hotplug removing an hvcs device, we need to ensure the hangup processing is done prior to exiting the remove function, so use tty_vhangup to do the hangup processing directly rather than using tty_hangup which simply schedules the hangup work for later execution. Signed-off-by: Brian King --- drivers/tty/hvc/hvcs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c index b28ddfc46e42..24541fc53625 100644 --- a/drivers/tty/hvc/hvcs.c +++ b/drivers/tty/hvc/hvcs.c @@ -815,12 +815,11 @@ static void hvcs_remove(struct vio_dev *dev) sysfs_remove_group(&dev->dev.kobj, &hvcs_attr_group); /* - * The hangup is a scheduled function which will auto chain call - * hvcs_hangup. The tty should always be valid at this time unless a + * The tty should always be valid at this time unless a * simultaneous tty close already cleaned up the hvcs_struct. */ if (tty) { - tty_hangup(tty); + tty_vhangup(tty); tty_kref_put(tty); } From patchwork Wed Feb 1 19:57:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian King X-Patchwork-Id: 649946 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F9ACC05027 for ; Wed, 1 Feb 2023 19:58:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232344AbjBAT61 (ORCPT ); Wed, 1 Feb 2023 14:58:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232277AbjBAT6K (ORCPT ); Wed, 1 Feb 2023 14:58:10 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4035F7A88 for ; Wed, 1 Feb 2023 11:58:04 -0800 (PST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 311Jqw7T004038; Wed, 1 Feb 2023 19:58:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=11jsw3bf4Kklb9Hv1uoFRsiJRYOXiYZundBhyj4+MSg=; b=IQYlCJIUDefXVAdawpD5cEdpdGxzekXuzq7KntzOaTvC/kGEcbRRwN4AYKzAXZhQ8+Br N4/ijcCMyQ6yvWwqaU0PZD8jzQQAs6Vc5lwK4Ekwwls3lJo2gL9o2NBQIxoDnGx+ciU3 Pm0dI2dKa+Yj2xZtlclCZs174aD09MDQ/96nJ4KBxhmzboj2KiXO4ylGKYddZVr8b+83 fWY/4d1Xr16j1tObaB1jHVvXXDEknk7fvaOh6H2Vcb38ruyvP0wgtuMxNxuOoKvrvOzF wUeRXpKXKq8Gf8tu637vBCnaF3SW0+Jr+Tc3rHMud7kkWnqQ6X1DIk02fi1qXyoMjYVT 3g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfxmng325-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:59 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 311JrVLw005595; Wed, 1 Feb 2023 19:57:59 GMT Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3nfxmng31x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:59 +0000 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 311ISKek008456; Wed, 1 Feb 2023 19:57:58 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([9.208.129.116]) by ppma04dal.us.ibm.com (PPS) with ESMTPS id 3ncvw2wdde-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Feb 2023 19:57:58 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 311JvvCW41484558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Feb 2023 19:57:57 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 091845805D; Wed, 1 Feb 2023 19:57:57 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8138058057; Wed, 1 Feb 2023 19:57:56 +0000 (GMT) Received: from li-6bf4d4cc-31f5-11b2-a85c-838e9310af65.ibm.com.com (unknown [9.211.132.88]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Feb 2023 19:57:56 +0000 (GMT) From: Brian King To: gregkh@linuxfoundation.org Cc: linuxppc-dev@lists.ozlabs.org, brking@pobox.com, mmc@linux.vnet.ibm.com, linux-serial@vger.kernel.org, Brian King Subject: [PATCH 6/6] hvcs: Synchronize hotplug remove with port free Date: Wed, 1 Feb 2023 13:57:43 -0600 Message-Id: <20230201195743.303163-7-brking@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230201195743.303163-1-brking@linux.vnet.ibm.com> References: <20230201195743.303163-1-brking@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3PMwp-rfG3qQ8P2nR3fiQXRJ_WoSc-5w X-Proofpoint-ORIG-GUID: 0sF9fk-RbrAnzrWH8YijpV8pW_V514kE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-01_04,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 adultscore=0 bulkscore=0 clxscore=1015 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302010166 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Synchronizes hotplug remove with the freeing of the port. This ensures we have freed all the memory associated with this port and are not leaking memory. Signed-off-by: Brian King --- drivers/tty/hvc/hvcs.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c index 24541fc53625..2b038d4b3a63 100644 --- a/drivers/tty/hvc/hvcs.c +++ b/drivers/tty/hvc/hvcs.c @@ -52,6 +52,7 @@ #include #include +#include #include #include #include @@ -285,6 +286,7 @@ struct hvcs_struct { char p_location_code[HVCS_CLC_LENGTH + 1]; /* CLC + Null Term */ struct list_head next; /* list management */ struct vio_dev *vdev; + struct completion *destroyed; }; static LIST_HEAD(hvcs_structs); @@ -658,11 +660,13 @@ static void hvcs_destruct_port(struct tty_port *p) { struct hvcs_struct *hvcsd = container_of(p, struct hvcs_struct, port); struct vio_dev *vdev; + struct completion *comp; unsigned long flags; spin_lock(&hvcs_structs_lock); spin_lock_irqsave(&hvcsd->lock, flags); + comp = hvcsd->destroyed; /* the list_del poisons the pointers */ list_del(&(hvcsd->next)); @@ -682,6 +686,7 @@ static void hvcs_destruct_port(struct tty_port *p) hvcsd->p_unit_address = 0; hvcsd->p_partition_ID = 0; + hvcsd->destroyed = NULL; hvcs_return_index(hvcsd->index); memset(&hvcsd->p_location_code[0], 0x00, HVCS_CLC_LENGTH + 1); @@ -689,6 +694,8 @@ static void hvcs_destruct_port(struct tty_port *p) spin_unlock(&hvcs_structs_lock); kfree(hvcsd); + if (comp) + complete(comp); } static const struct tty_port_operations hvcs_port_ops = { @@ -795,6 +802,7 @@ static int hvcs_probe( static void hvcs_remove(struct vio_dev *dev) { struct hvcs_struct *hvcsd = dev_get_drvdata(&dev->dev); + DECLARE_COMPLETION_ONSTACK(comp); unsigned long flags; struct tty_struct *tty; @@ -802,16 +810,11 @@ static void hvcs_remove(struct vio_dev *dev) spin_lock_irqsave(&hvcsd->lock, flags); + hvcsd->destroyed = ∁ tty = tty_port_tty_get(&hvcsd->port); spin_unlock_irqrestore(&hvcsd->lock, flags); - /* - * Let the last holder of this object cause it to be removed, which - * would probably be tty_hangup below. - */ - tty_port_put(&hvcsd->port); - sysfs_remove_group(&dev->dev.kobj, &hvcs_attr_group); /* @@ -823,6 +826,8 @@ static void hvcs_remove(struct vio_dev *dev) tty_kref_put(tty); } + tty_port_put(&hvcsd->port); + wait_for_completion(&comp); printk(KERN_INFO "HVCS: vty-server@%X removed from the" " vio bus.\n", dev->unit_address); }; @@ -1172,7 +1177,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp) hvcsd = tty->driver_data; spin_lock_irqsave(&hvcsd->lock, flags); - if (--hvcsd->port.count == 0) { + if (hvcsd->port.count == 0) { + spin_unlock_irqrestore(&hvcsd->lock, flags); + return; + } else if (--hvcsd->port.count == 0) { vio_disable_interrupts(hvcsd->vdev); @@ -1228,11 +1236,7 @@ static void hvcs_hangup(struct tty_struct * tty) vio_disable_interrupts(hvcsd->vdev); hvcsd->todo_mask = 0; - - /* I don't think the tty needs the hvcs_struct pointer after a hangup */ - tty->driver_data = NULL; hvcsd->port.tty = NULL; - hvcsd->port.count = 0; /* This will drop any buffered data on the floor which is OK in a hangup