Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2163264iof; Tue, 7 Jun 2022 21:51:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyubjfw569taoAKDtswY8JBtNcejIP+wnNa2AfoBvmk2dl+PQH0JXvdq0xj/dh9gDXDm7zy X-Received: by 2002:a17:90b:3841:b0:1e2:f16a:a117 with SMTP id nl1-20020a17090b384100b001e2f16aa117mr55237000pjb.130.1654663909795; Tue, 07 Jun 2022 21:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654663909; cv=none; d=google.com; s=arc-20160816; b=sfuhQRVfWpuEuC5Sol9vNDzmE5noUgmd0TC/4QqZh8b2XwyNDa67Y7VNMl0movW+Nd /75QH/eh+TvuZlAZyiUG0Jxrn3c9OyL10B8dg+jtxnTG2+qm0pZ/uhzjkkbFMLb+B2cz fg0arW+tjSFYBNa9QBwyIxtRBdOsmlJLIUSJYNbY8YSEoxFmwfkDISFKMcbyEgxkyGvA ghDJesHkQ03E5JakqaFejA5tm8DvifAmHnbxa86VhMTfr4YGPX8Rp8LjA8BVZl4c7VWy kYYk2QEYK/j1qHOPK/jfJzQQc7lwdOPj2ueNPC/f58Hj8w2d3dFeFViwgpTPB87Dpcoo Uftg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FWNJ/0llFFqdnJR8zr6CsAqGXBIank7+XvDB2F7E6w8=; b=JKMPL94jxq3pOohplA72O9HS0YxhaJ0GxIdwN2LLwcEaAl6P8Jsp5NNXIzTk7yqYhN g/sz/hjTZqsLvkc76NWbrvd6Olx0I/hZpH5wHsn0L8kLiOrFia5Hqf6RGBJXKW71EkaK OdfTqr6olmmmfImXGTpnfHG5gh3iXusXcaHxICUXEc+c4EgizoCuLk59u1YCd91u8WVK VNlZSE5FXFfYx9uA5MVL5oI2VlDRdG2yEuBciNfyJfKMPieci5tJR3u+mSF8d5hpqbol dTaryFxOQAbbYDWU2HPBXSHGHLp2ykWAXe2SMn1ZrQkndYzxgJ5+hNuKUnnv8owWC+bT ye+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SVk8bJNp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z28-20020aa79e5c000000b004fa3a8e007fsi24688789pfq.310.2022.06.07.21.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:51:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SVk8bJNp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 56BD64516EA; Tue, 7 Jun 2022 21:21:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349818AbiFGSAb (ORCPT + 99 others); Tue, 7 Jun 2022 14:00:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348560AbiFGRlK (ORCPT ); Tue, 7 Jun 2022 13:41:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18B3B120890; Tue, 7 Jun 2022 10:34:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5226961543; Tue, 7 Jun 2022 17:33:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58D1CC385A5; Tue, 7 Jun 2022 17:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623208; bh=5nof6Jt2ksDAMb5Ln0YlWKqlrv9Jw3OM28OWQlEtXTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SVk8bJNpXyKctqTipWE1xcDgv2VeVQ5Bva0UonvtcbZFOecFvQLwSfIckBcH2blnk tKr7Nto7LH99/3GdklCpJ/WVs98sOKuVdh905/i6bmnZFN66p+T6oXEtx/e35SBs2e GHoy+hohh0eFQ+/Yy/xczjSoGg1+UMnptH50WkQo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Michal Hocko , David Hildenbrand , "Rafael J. Wysocki" , Scott Cheloha , Nathan Lynch , Andrew Morton , Sasha Levin Subject: [PATCH 5.10 293/452] drivers/base/memory: fix an unlikely reference counting issue in __add_memory_block() Date: Tue, 7 Jun 2022 19:02:30 +0200 Message-Id: <20220607164917.284771638@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET [ Upstream commit f47f758cff59c68015d6b9b9c077110df7c2c828 ] __add_memory_block() calls both put_device() and device_unregister() when storing the memory block into the xarray. This is incorrect because xarray doesn't take an additional reference and device_unregister() already calls put_device(). Triggering the issue looks really unlikely and its only effect should be to log a spurious warning about a ref counted issue. Link: https://lkml.kernel.org/r/d44c63d78affe844f020dc02ad6af29abc448fc4.1650611702.git.christophe.jaillet@wanadoo.fr Fixes: 4fb6eabf1037 ("drivers/base/memory.c: cache memory blocks in xarray to accelerate lookup") Signed-off-by: Christophe JAILLET Acked-by: Michal Hocko Reviewed-by: David Hildenbrand Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Scott Cheloha Cc: Nathan Lynch Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- drivers/base/memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index de058d15b33e..49eb14271f28 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -560,10 +560,9 @@ int register_memory(struct memory_block *memory) } ret = xa_err(xa_store(&memory_blocks, memory->dev.id, memory, GFP_KERNEL)); - if (ret) { - put_device(&memory->dev); + if (ret) device_unregister(&memory->dev); - } + return ret; } -- 2.35.1