From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B45131C14; Fri, 13 Sep 2024 17:36:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726248988; cv=none; b=OSw/IQOH8PGfjV3Ad9m9uzgJli0v9lFeKb7XdyXIkHGbzCRs9Dz/EZF9F59butZZepiEN2DWYeDj5z057sV08ZLTEcyQzf6BrhWOEMUAFMsB4BLNinCQJtWEmXsGCT6BrncYHDaIsDE6QwdgZpIUHUXzQH6AcXLhDzjVg2wjqVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726248988; c=relaxed/simple; bh=qmKkdgRohILDSp67u4JvMpfqmmsKkaGVM+ZS7KGOUMU=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Mm038IEoOLRR/d/jPPPGM9HYH8fCKyvODSD8xmxp79FYvBltbAKbP8aRqO9g34eMNDiYYlIL6v6jn3P2urkcNm7QBuV6YnROmyjrGf27wJwOyCH5bPFZHe5B7/AKOnpxr6psaDDzO9IYTqp/Vk0WvcKh/x7Dx37lzrxtairCr+Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4X51b74hD8z6K5V9; Sat, 14 Sep 2024 01:32:19 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 3F4D5140A77; Sat, 14 Sep 2024 01:36:24 +0800 (CST) Received: from localhost (10.48.150.243) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 13 Sep 2024 19:36:23 +0200 Date: Fri, 13 Sep 2024 18:36:21 +0100 From: Jonathan Cameron To: CC: , , , , , , , , , Alejandro Lucero Subject: Re: [PATCH v3 07/20] cxl: harden resource_contains checks to handle zero size resources Message-ID: <20240913183621.000024f0@Huawei.com> In-Reply-To: <20240907081836.5801-8-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> <20240907081836.5801-8-alejandro.lucero-palau@amd.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml100006.china.huawei.com (7.191.160.224) To frapeml500008.china.huawei.com (7.182.85.71) On Sat, 7 Sep 2024 09:18:23 +0100 wrote: > From: Alejandro Lucero > > For a resource defined with size zero, resource_contains returns > always true. > > Add resource size check before using it. > > Signed-off-by: Alejandro Lucero > --- > drivers/cxl/core/hdm.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c > index 3df10517a327..953a5f86a43f 100644 > --- a/drivers/cxl/core/hdm.c > +++ b/drivers/cxl/core/hdm.c > @@ -327,10 +327,11 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled, > cxled->dpa_res = res; > cxled->skip = skipped; > > - if (resource_contains(&cxlds->pmem_res, res)) > + if ((resource_size(&cxlds->pmem_res)) && (resource_contains(&cxlds->pmem_res, res))) { Excess brackets + I'd break that over two lines. > cxled->mode = CXL_DECODER_PMEM; > - else if (resource_contains(&cxlds->ram_res, res)) > + } else if ((resource_size(&cxlds->ram_res)) && (resource_contains(&cxlds->ram_res, res))) { Same here, > cxled->mode = CXL_DECODER_RAM; > + } > else { > dev_warn(dev, "decoder%d.%d: %pr mixed mode not supported\n", > port->id, cxled->cxld.id, cxled->dpa_res);