From patchwork Tue Nov 28 18:30:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshit Mogalapalli X-Patchwork-Id: 170912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp4136214vqx; Tue, 28 Nov 2023 10:31:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBH8+ELxZsPXTJPOIVP4E3Fa+IANCxHYRiIjHcUVCBoHy2w0jAopvWhi/GFJfxHcbPQGzR X-Received: by 2002:a05:6a00:2791:b0:6c4:cf33:cbe8 with SMTP id bd17-20020a056a00279100b006c4cf33cbe8mr14751028pfb.6.1701196289138; Tue, 28 Nov 2023 10:31:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701196289; cv=none; d=google.com; s=arc-20160816; b=C++ym3Qg58CTI9bxRWw4SPP+nZaR01hjhbpElxEX8Fdh6qULE1a666oAyY22zVtEBf 7MJB9LmgeEc9UZ/0nYM1ALZcQhE6/xk+WeIQYrXp+nT9+zvGm8xbm3zi1o3WR6fkrcpE am/HD/3GZ4FkuyMNYb+JPE1f4hgk7k6CY7NU832Rb6Fyk9bc45ki9dC9eJ+zDrVEPS7F 7eV1YUBHb5KMUKCeWNTBjNrbcpUJowyaLOKishTDxb3Rs9EdZBFMvS8EtatzSl0Kl2Wh xHMox2b8neoAj0C2CGML/6pFBwZD/2MyCeS9ExN9m3BDO7Nx3uO0UyxrqFGm/ynRxlAO +4Ew== 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=R0HKGf7zq1Qv/2c20PBwtieJjUtw3OOPPPuqInlI6kY=; fh=GPFxx18gSXPtTEl+SqcSG5zb7VLKsSnzqKKn9ZmodE0=; b=SrJunhT46YhomqCxk18zEDejcL9UcbdQGoybl9u8jjqDSawiAgP4yyOeKmEqHB37l9 J1GOYcgRvHfOnpnExWeuI+2LdlysasctVDTNbEuMYuhnFk9wEVds4nMsNhBPpFxdCvoM cUOtIQZMw0jzVaFvOcYQ/NOknOjoS0acjxZalbHvqxtGM4UdyJLcRBTRaqAY3ufDof3G 5LWkdvcBjkde0cnDYQtRPvjbtfIu8J6VGK+uzjS5jhWm40jmyRFubgBiFscBl/8Zzl4L pSYT5ziNenvuJPPppcIAayuoC1LmOIj+OnGnaxhkU/SV9FnF0vq8tqvwPLi6211XumYx 1S/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=ImlU2QsJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id w1-20020a626201000000b0068fcc84dda7si11726691pfb.327.2023.11.28.10.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 10:31:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=ImlU2QsJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 6694A8050036; Tue, 28 Nov 2023 10:31:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345847AbjK1SbF (ORCPT + 99 others); Tue, 28 Nov 2023 13:31:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229921AbjK1SbE (ORCPT ); Tue, 28 Nov 2023 13:31:04 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 381649D; Tue, 28 Nov 2023 10:31:10 -0800 (PST) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3ASI0rr2023949; Tue, 28 Nov 2023 18:30:57 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=R0HKGf7zq1Qv/2c20PBwtieJjUtw3OOPPPuqInlI6kY=; b=ImlU2QsJKc2ndJebUOQmNrHoTV62oEf32kCkcj3ZZXHh4WFm3Ccx7fhrMZBHSPpYBz/L R+IKbpbAk9S0gu55CCd8MgFy6oAAhjfp5mM5FSsxBtPCsTh+8izPfc7fXtNp/+XcuW7+ 6CRFEYc93ASCHVGHsFVLKUwg1rep/yrxbeVGBR/G+vxxfBZMrLglpr+QmMCFbBzO5xeZ FOYrfaE8vOHSt2/ip5vvq+VkuApRNnDFDSlNXixfMsXL1Og/eUapD+b41e3f7cmXwdip HxFrZzhjw4dVJpDcYCuzOBcOfYo6/xpzFCcg/2x4t7j9LAPt8w3ov8C/0hm/Eokar/pG kQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uk7h2phb4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Nov 2023 18:30:57 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3ASHZjNT026444; Tue, 28 Nov 2023 18:30:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uk7c72s7x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Nov 2023 18:30:56 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3ASIUuVD010887; Tue, 28 Nov 2023 18:30:56 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3uk7c72s1g-1; Tue, 28 Nov 2023 18:30:56 +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, stable@vger.kernel.org Subject: [PATCH v2 1/2] EDAC/device_sysfs: Fix calling kobject_put() with ->state_initialized unset Date: Tue, 28 Nov 2023 10:30:35 -0800 Message-ID: <20231128183037.3395755-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.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-28_21,2023-11-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311280148 X-Proofpoint-GUID: AdGf5QDCj5RZZurKdF2t5XMWw_j8QqTS X-Proofpoint-ORIG-GUID: AdGf5QDCj5RZZurKdF2t5XMWw_j8QqTS 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 28 Nov 2023 10:31:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783833600455392800 X-GMAIL-MSGID: 1783833600455392800 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. Cc: Fixes: cb4a0bec0bb9 ("EDAC/sysfs: move to use bus_get_dev_root()") Signed-off-by: Harshit Mogalapalli --- This is based on static analysis and only compile tested. v1->v2: Resend as a patchset as they are two similar bugs. --- 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; }