From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C80D2C6FD1D for ; Thu, 30 Mar 2023 17:19:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232316AbjC3RTb (ORCPT ); Thu, 30 Mar 2023 13:19:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232294AbjC3RT0 (ORCPT ); Thu, 30 Mar 2023 13:19:26 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEF23EB64 for ; Thu, 30 Mar 2023 10:19:19 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4PnVWL29BVz6J7wF; Fri, 31 Mar 2023 01:18:38 +0800 (CST) Received: from localhost (10.48.159.148) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 30 Mar 2023 18:19:17 +0100 Date: Thu, 30 Mar 2023 18:19:16 +0100 From: Jonathan Cameron To: Dan Williams CC: , Dave Jiang Subject: Re: [PATCH] cxl/hdm: Avoid NULL deref when component registers are missing Message-ID: <20230330181916.00007fb8@Huawei.com> In-Reply-To: <168012574357.221280.5001364964799725366.stgit@dwillia2-xfh.jf.intel.com> References: <168012574357.221280.5001364964799725366.stgit@dwillia2-xfh.jf.intel.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.48.159.148] X-ClientProxiedBy: lhrpeml100005.china.huawei.com (7.191.160.25) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org On Wed, 29 Mar 2023 14:35:43 -0700 Dan Williams wrote: > The cxl_port driver attempts to support endpoint devices that do not > advertise a component register block, but by inspection > devm_cxl_setup_hdm() passes a NULL @crb to helper functions that should > be skipped. > > Return early and skip setting target_count since that is only relevant > for switch decoders, not endpoint decoders. This is a good observation. It would be nice to not read it for the HDM decoder path either. Obviously we don't use it so that doesn't do any harm, but to someone reading the code it looks like we care about the value. I'm not immediately sure how we'd establish at this layer that the HDM decoder is a switch or HB one though.. > > Fixes: 757f6448b100 ("cxl/hdm: Fix double allocation of @cxlhdm") > Tested-by: Dave Jiang > Signed-off-by: Dan Williams Patch looks fine to me. Reviewed-by: Jonathan Cameron > --- > drivers/cxl/core/hdm.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c > index 5293fe13fce3..cc123996b1a4 100644 > --- a/drivers/cxl/core/hdm.c > +++ b/drivers/cxl/core/hdm.c > @@ -123,7 +123,7 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port, > crb = ioremap(port->component_reg_phys, CXL_COMPONENT_REG_BLOCK_SIZE); > if (!crb && info && info->mem_enabled) { > cxlhdm->decoder_count = info->ranges; > - cxlhdm->target_count = info->ranges; > + return cxlhdm; > } else if (!crb) { > dev_err(dev, "No component registers mapped\n"); > return ERR_PTR(-ENXIO); >