Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3829050rdh; Tue, 28 Nov 2023 05:10:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEebgb8rzjV4C3Ep7ypXi4gZOmv01W9uC+SHtp3LrBr/bKOJfNqIi9iQHQTIIXSL+NQKzc4 X-Received: by 2002:a92:d391:0:b0:35c:f2f6:7b15 with SMTP id o17-20020a92d391000000b0035cf2f67b15mr5339070ilo.17.1701177043052; Tue, 28 Nov 2023 05:10:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701177043; cv=none; d=google.com; s=arc-20160816; b=V/ovnxrHNfr8aFnJ9xF5GToPsXGTv/eb1oPtmADqiVGmVbLFLlA60Ce+EHh9ABV12u o6w2ugHK8b/74N9LlaYp6+Ui3bmtI1034o4Y0bulzcdVS2JKpgFVVjlHYzpUcizfOBmE Z3OAKktwTOBwG2EM/TLWa9m8Uqy7pBpSLzhndaJpspA9t3fnLxT16vMQbz/GBTfBhbG8 TPRn3Hij2P9/cWPKRCk2547PyMkUeQojShxtOYKNNGK6nt4QaFO7o6BxZoXdYul5U4ID aSieLcUV8Wq7etL3825iACzg8na0/TTxHoFHY4J0reU/+76raOlhdeHie2mEBp4FKQcs SsQw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=BzNJ9iRGfz25bP31jKWHUOIixIrbax65I5/G31Hvt9w=; fh=HwsKBgO84BpY/XE0B+pTAbQo9XTqzaM3c7ZGojTa4EU=; b=wpz0NpIg2w2/AKxNY/v3N9vn0BG5j3peL1Mwz/NAnQGM+4o4HD9eAfUNwKcLlkOH8k r+YJ167813e5mEldLPZYgSEIcng+GYzaWGTVLjUq9lzoAzEEmRaeymY7oEpnVckk8uUM bdmEKj32BTPxiYCFESwXRRRF/k/PLzi/AlGrF06pYyxp/tLhfnlDGPKQ9gDja1gqzU6l m2pkOJBYX+WbdwETep4ZjBshIhfwCWMCW2GZrnxMfgrsDJ6weRJnWsXqXzSXBNHtmg9A AW78xJiBLlNz9pkIGcdUuOEMjps/exzpHZr0tHXznubq70pbKVrkBY5o6hgnp5pcII0E MpCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=bxTo9+80; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id d11-20020a631d4b000000b005c1ce3c9608si11302948pgm.756.2023.11.28.05.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 05:10:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=bxTo9+80; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 113E6804922F; Tue, 28 Nov 2023 05:10:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344891AbjK1NKL (ORCPT + 99 others); Tue, 28 Nov 2023 08:10:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344871AbjK1NKJ (ORCPT ); Tue, 28 Nov 2023 08:10:09 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C60BD51; Tue, 28 Nov 2023 05:10:16 -0800 (PST) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ASBT54N000874; Tue, 28 Nov 2023 13:09:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2023-11-20; bh=BzNJ9iRGfz25bP31jKWHUOIixIrbax65I5/G31Hvt9w=; b=bxTo9+80AYbBVv/Kv7UPx0/iXHVVu2a993TxlSvclY+1J1j5/O3pmGUw2d7QKJc6d+On lsm7lEMkO5knNkvIP4IDQGTelfq3zp9Fk2Nkn6LjnqefgcyZPsdvsPjIsIw1vgEhdj99 +W+VBKg3LQUSFUnxsFVfhzdlN9zVN0Wu617l3XL86ltVgIUCUXHZcvxQHfM4G+8BXjo6 zkWwp9DQFrNCtvE5wazZw2tPPG9/RhpZr7CNUp2Q5eMTTNScR7msIDoSspozSqs1YiT6 iZ72fYFZ1sfdgEDQbIgRUDmNP7xXhpCQZaYU4R8qagV9WfZhwTjO9auU/DDc8DHw5gmj CQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uk8yd5rqa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Nov 2023 13:09:58 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3ASD0uB9027071; Tue, 28 Nov 2023 13:09:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3uk7cd34ne-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Nov 2023 13:09:57 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ASD9vau005694; Tue, 28 Nov 2023 13:09:57 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3uk7cd34m3-1; Tue, 28 Nov 2023 13:09:57 +0000 From: Harshit Mogalapalli To: Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter , Greg Kroah-Hartman , linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dan.carpenter@linaro.org, kernel-janitors@vger.kernel.org, error27@gmail.com, harshit.m.mogalapalli@oracle.com Subject: [PATCH] EDAC/sysfs: Fix calling kobject_put() without kobj initialization Date: Tue, 28 Nov 2023 05:09:52 -0800 Message-ID: <20231128130952.3372794-1-harshit.m.mogalapalli@oracle.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-28_14,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311280105 X-Proofpoint-ORIG-GUID: OjPUr0MfaKZ5C1yf0Hi4U5w1zAH6OmQ9 X-Proofpoint-GUID: OjPUr0MfaKZ5C1yf0Hi4U5w1zAH6OmQ9 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 28 Nov 2023 05:10:23 -0800 (PST) In edac_pci_main_kobj_setup() when dev_root is NULL, kobject_init_and_add() is not called. if (err) { // err = -ENODEV; edac_dbg(1, "Failed to register '.../edac/pci'\n"); goto kobject_init_and_add_fail; // call to kobject_put() } This will cause a runtime warning in kobject_put() if the above happens. Warning: "kobject: '%s' (%p): is not initialized, yet kobject_put() is being called." Fix the error handling to avoid the above possible situation. Fixes: cb4a0bec0bb9 ("EDAC/sysfs: move to use bus_get_dev_root()") Signed-off-by: Harshit Mogalapalli --- This is based on static analysis with Smatch and only compile tested. --- drivers/edac/edac_pci_sysfs.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c index 901d4cd3ca38..71a0d4b9c2cf 100644 --- a/drivers/edac/edac_pci_sysfs.c +++ b/drivers/edac/edac_pci_sysfs.c @@ -370,12 +370,14 @@ static int edac_pci_main_kobj_setup(void) /* Instanstiate the pci object */ dev_root = bus_get_dev_root(edac_subsys); - if (dev_root) { - err = kobject_init_and_add(edac_pci_top_main_kobj, - &ktype_edac_pci_main_kobj, - &dev_root->kobj, "pci"); - put_device(dev_root); - } + if (!dev_root) + goto kzalloc_fail; + + err = kobject_init_and_add(edac_pci_top_main_kobj, + &ktype_edac_pci_main_kobj, + &dev_root->kobj, "pci"); + put_device(dev_root); + if (err) { edac_dbg(1, "Failed to register '.../edac/pci'\n"); goto kobject_init_and_add_fail; -- 2.39.3