From patchwork Mon Nov 27 07:25:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshit Mogalapalli X-Patchwork-Id: 170037 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp2908484vqx; Sun, 26 Nov 2023 23:26:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfoEaYW4sLNVhyWXczKcj7Mupzne1AEeH4UzLdPfPrbPuCI8oTUjH7e8uilgW6thfEbE5A X-Received: by 2002:a05:6870:c68b:b0:1fa:d0:57b0 with SMTP id cv11-20020a056870c68b00b001fa00d057b0mr11275232oab.52.1701069988722; Sun, 26 Nov 2023 23:26:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701069988; cv=none; d=google.com; s=arc-20160816; b=qlWnuRam69Ss4PZ5m8Hb0hpVBKRmaaJQqT+UaNP12BpBDH/OahwRFzyTs984wMaBH5 oRRplRiRRmlhKm9HPHLRLrTUGOi+/UKtAc3KhrnEZDGy4vUCqmV2Ec2KZ7VxeLhqkjtl +FHMkBZ6JkoUA5g/JvIqsUgivQWgRW0tfGX0ZTsH1mRbj5gaz2Bz3ry5cpMeoPbtLKRL Cd1IRw9JLl7LTKi/+OHsKQ9reCNnqfaMjBD1+SKEu0kb53wBwVaUS42XHkXIl+mke/SV JqKd591atwhx7cKWiYm+Uit+Nv5wcCj3SePg5F2obJl1dIjLLWQphV+egtAb6HipELfi g4zQ== 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=nfPRoM43naBHTjzsRwQ3luSTvIcWFtQTc4Nk6Xy4q0Y=; fh=HwsKBgO84BpY/XE0B+pTAbQo9XTqzaM3c7ZGojTa4EU=; b=tvu/n5747skEGUTo1igeUcPofoKQcC0zS6v4rpXWMCZRO60yWfiR3XzOW9n1ZK4E2D c8Vi5nCz6gnl+ITxKTDmjeYydqy8q7aH3X506B+smF+buVdzcOVbxHTjkL/vnHbf9cVN W9P/4DeqmglW85S8SGE5F5+ETD5sApJfYGpu68AlrcupVB7/5MylQ91SAW7riJQesaC8 OB9etnRs3wgo3nWCA/65H4twgi51o1Jp7Zha/lmZnv+INibdf+sp0hX/d+8ljrBqu+Hw a17sbETHFVZMqK0C0vByXIUAyR3G1WanG64poLA8dUcX4dI7lrc61gY+upnPzoFXWPIF 4icA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=hDRlHv8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id x23-20020aa79417000000b006cb6cc0f42dsi8502735pfo.405.2023.11.26.23.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 23:26:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=hDRlHv8T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id B8CF88068995; Sun, 26 Nov 2023 23:26:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbjK0H0Q (ORCPT + 99 others); Mon, 27 Nov 2023 02:26:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjK0H0O (ORCPT ); Mon, 27 Nov 2023 02:26:14 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6901412D; Sun, 26 Nov 2023 23:26:20 -0800 (PST) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AR6Y2P6016850; Mon, 27 Nov 2023 07:26:03 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=nfPRoM43naBHTjzsRwQ3luSTvIcWFtQTc4Nk6Xy4q0Y=; b=hDRlHv8TI6GI7DBqtoKP1+qqNjKQaqz3+dM3eUcjRBy3NdjcHCHje4jekK/ymBpiE1Wm LpjGc7/5/lC4boyQbpTHGCBfGC+/5ZesCWCRcc7Sqwbvrc001fiIGBNMEXBj8OW/jMMG IHtPX5HpO9d+AZ65RXBebIHec7QODyjp4/tMVexPiDSuaSlxfuElW9ZVmPw8eDnN2iR1 5WOf2HiS4n0sDqBKBNzPGr2SEg3IMOuuL8XCaXQ0Nt72cbMfy2TQIJsm8D1zmF3ASnNn jbotjyu+/6lHt2zoie5Oi0DFSVtPaYcGVzxkXsqGRvdyc7tVGu6+yWgy8sHaQ6hjWlvO 4g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uk7q4294n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 07:26:03 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3AR6xMvD009302; Mon, 27 Nov 2023 07:26:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uk7c4p5yg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Nov 2023 07:26:02 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3AR7Q1DM034619; Mon, 27 Nov 2023 07:26:01 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3uk7c4p5y2-1; Mon, 27 Nov 2023 07:26:01 +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 kobj_put() with ->state_initialized unset Date: Sun, 26 Nov 2023 23:25:58 -0800 Message-ID: <20231127072558.2999920-1-harshit.m.mogalapalli@oracle.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-27_05,2023-11-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311270051 X-Proofpoint-ORIG-GUID: fc-arH-CXMoGs7vLR2cpWWHa3D19-A8A X-Proofpoint-GUID: fc-arH-CXMoGs7vLR2cpWWHa3D19-A8A X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Sun, 26 Nov 2023 23:26:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783701164558750692 X-GMAIL-MSGID: 1783701164558750692 In edac_device_register_sysfs_main_kobj(), when dev_root is NULL, kobject_init_and_add() is not called. if (err) { // err = -ENODEV edac_dbg(1, "Failed to register '.../edac/%s'\n", edac_dev->name); goto err_kobj_reg; // This calls kobj_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 only compile tested and based on static analysis with Smatch. --- drivers/edac/edac_device_sysfs.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c index 010c26be5846..4cac14cbdb60 100644 --- a/drivers/edac/edac_device_sysfs.c +++ b/drivers/edac/edac_device_sysfs.c @@ -253,11 +253,13 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) /* register */ dev_root = bus_get_dev_root(edac_subsys); - if (dev_root) { - err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl, - &dev_root->kobj, "%s", edac_dev->name); - put_device(dev_root); - } + if (!dev_root) + goto module_put; + + err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl, + &dev_root->kobj, "%s", edac_dev->name); + put_device(dev_root); + if (err) { edac_dbg(1, "Failed to register '.../edac/%s'\n", edac_dev->name); @@ -276,8 +278,8 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev) /* Error exit stack */ err_kobj_reg: kobject_put(&edac_dev->kobj); +module_put: module_put(edac_dev->owner); - err_out: return err; }