Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3627627pxj; Mon, 21 Jun 2021 03:06:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpyh6iwDSsD4LgWMjUXNrn/LeJKZBf/Cicjq/qMvrnPEjfXHQIV8qH2GLjsreUP1uPUCUT X-Received: by 2002:a92:1942:: with SMTP id e2mr11937144ilm.4.1624269962784; Mon, 21 Jun 2021 03:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624269962; cv=none; d=google.com; s=arc-20160816; b=AUMKJ4Wc6tQeXiV1rcZYSj65hip6USHillmeQ4mva/lBOmMGKqvBPYcfTGMOmrPbbY baS4Z5QEbE+OsrIQYR22cei7hO+MSjvjxrJIzIOkCDWKrECo15fwmkfCawPi1kYoy9yu zNRZWECPG/G8hl6wi22E7V5lTr3NJbGpdr6kkGBU9Yw+TcIWP/oD4uSZccz/4k25ZkkT uUBMFc9wNquDO1Hi3qwrZpT84j6irWcqYDiQd2UULzX5iILvflIa2mxt3zoogEh455I/ jYl7HW07lugOdj38pC02GJ5C4YeBfMEEjKyalGMKOuQuzMxT7zNMOs97qNJ82Yo84dVX UPAw== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=YeQ6G+Xiv94s6yau5B40Z1/XrGaewAAJ4ZmFfwdOEgE=; b=CHgKu2MDjvSRb4bW0CDqo6caHJPc3drKf5EKBINQ3MtAFZcAC3zS8xCtUb2iR9GDWj 6O8RX0dG1Hbv72oR7Z9YrVhuJPTcQlJCYmlYvxg56X/snCx/tEBw3XpyEh9ojhFZbktY mC1AVLV2HmbQWpUG0WNAxE58wZNHb4kVGJRsOA5SbsTlo0isrRMZsYJPC+WIiLDfjc71 IY9PRZThFsIfBtFSvhJ0dH2qqTPW571IwwGVQBgaYrBeE+ODE0ZERKPxG8+9Yd5EvEIV OviAmtCCCQUNaUMK491bC8DAbycSs9JpnT7e22ItKF/WUf60N7/AcaYHsUJFqOOmpn5M 7oIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=jE+28dvy; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t17si11566022ilp.132.2021.06.21.03.05.49; Mon, 21 Jun 2021 03:06:02 -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=@ibm.com header.s=pp1 header.b=jE+28dvy; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbhFUKHK (ORCPT + 99 others); Mon, 21 Jun 2021 06:07:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:50694 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229621AbhFUKHJ (ORCPT ); Mon, 21 Jun 2021 06:07:09 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15LA4k69039573; Mon, 21 Jun 2021 06:04:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pp1; bh=YeQ6G+Xiv94s6yau5B40Z1/XrGaewAAJ4ZmFfwdOEgE=; b=jE+28dvyg6ZxmW0w2B13PT8OjHCfVgMv8RUo9mz+/ESrxay34l1s0NIGpnMWQSJxH9D1 WrZEGhkInTLYgTwo9Y2sjuWjKX3oFPm4zziqoeoXAjoWfnbuV2PPh0C/TxXTbJATRk0M +4HLsoJFwAeZ+cQe7AqqllwBf0aK5m0AOMqokGmpFU3GelJpHZBYSeqLL8kUg4z7RsSH 4k1ot/ykgZnwEzE2WvCKtOK3vZLvVQccQEUpEpJd5HsVK1XCSGmWaUOuHGVKcv1RhmXJ TWQxw3ciqZdTSX/SGxeWS6VvpQmDuh5pxBnD4Cbj9expvE6Tm7dtZCPTg+DeoRM/6ipJ ZQ== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 39aqrpsnvq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Jun 2021 06:04:49 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 15LA4P9l002485; Mon, 21 Jun 2021 10:04:38 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma05fra.de.ibm.com with ESMTP id 3998788eg3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Jun 2021 10:04:37 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 15LA4YqK32375048 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Jun 2021 10:04:34 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9878E4204C; Mon, 21 Jun 2021 10:04:34 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 314AE4203F; Mon, 21 Jun 2021 10:04:34 +0000 (GMT) Received: from li-e979b1cc-23ba-11b2-a85c-dfd230f6cf82 (unknown [9.171.30.36]) by d06av24.portsmouth.uk.ibm.com (Postfix) with SMTP; Mon, 21 Jun 2021 10:04:34 +0000 (GMT) Date: Mon, 21 Jun 2021 12:04:32 +0200 From: Halil Pasic To: "Jason J. Herne" Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, akrowiak@linux.ibm.com, jgg@nvidia.com Subject: Re: [PATCH v2] s390/vfio-ap: Fix module unload memory leak of matrix_dev Message-ID: <20210621120432.0e6d2839.pasic@linux.ibm.com> In-Reply-To: <20210618171255.2025-1-jjherne@linux.ibm.com> References: <20210618171255.2025-1-jjherne@linux.ibm.com> Organization: IBM X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: oZ_td83_RAcwouGfS2-U13mHpY-kgWek X-Proofpoint-ORIG-GUID: oZ_td83_RAcwouGfS2-U13mHpY-kgWek X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-06-21_03:2021-06-21,2021-06-21 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 mlxscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106210059 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 18 Jun 2021 13:12:55 -0400 "Jason J. Herne" wrote: > vfio_ap_matrix_dev_release is shadowing the global matrix_dev with a NULL > pointer. Driver data for the matrix device is never set and so > dev_get_drvdata() always returns NULL. When release is called we end up > not freeing matrix_dev. The fix is to remove the shadow variable and get > the correct pointer from the device using container_of. We'll also NULL > the global to prevent any future use. > > Signed-off-by: Jason J. Herne > --- > drivers/s390/crypto/vfio_ap_drv.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c > index 7dc72cb718b0..40e66cb363d1 100644 > --- a/drivers/s390/crypto/vfio_ap_drv.c > +++ b/drivers/s390/crypto/vfio_ap_drv.c > @@ -82,9 +82,8 @@ static void vfio_ap_queue_dev_remove(struct ap_device *apdev) > > static void vfio_ap_matrix_dev_release(struct device *dev) > { > - struct ap_matrix_dev *matrix_dev = dev_get_drvdata(dev); > - > - kfree(matrix_dev); > + kfree(container_of(dev, struct ap_matrix_dev, device)); > + matrix_dev = NULL; Reviewed-by: Halil Pasic I'm not sure nulling the global here buys us anything (especially after the kfree()). But it does not hurt either, so I'm fine with it. Style wise I think vfio_ap_matrix_dev_destroy() is a better place for the nulling IMHO, as it is dealing with module global state. Regards, Halil > } > > static int matrix_bus_match(struct device *dev, struct device_driver *drv)