linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Huisong Li <lihuisong@huawei.com>
Cc: <xuwei5@hisilicon.com>, <linux-kernel@vger.kernel.org>,
	<soc@kernel.org>, <linux-arm-kernel@lists.infradead.org>,
	<krzk@kernel.org>, <wanghuiqiang@huawei.com>,
	<liuyonglong@huawei.com>
Subject: Re: [PATCH v2 3/6] soc: hisilicon: kunpeng_hccs: Add the check for base address and size of shared memory
Date: Fri, 23 Aug 2024 09:38:58 +0100	[thread overview]
Message-ID: <20240823093858.00007047@Huawei.com> (raw)
In-Reply-To: <20240823031059.32579-4-lihuisong@huawei.com>

On Fri, 23 Aug 2024 11:10:56 +0800
Huisong Li <lihuisong@huawei.com> wrote:

> If the shmem_base_addr from PCCT is zero, hccs_register_pcc_channel will
> return success. And then driver will access to illegal address when send
> PCC command. In addition, the size of shared memory used for communication
> between driver and platform is fixed, namely 64 Bytes which is
> unchangeable. So add the verification for them.
> 
As with previous, make it clear if this hardening or fix
fix to catch a problem on shipping hardware (I assume not, but you never
know!)

A comment on existing code inline.  Not a suggestion for a change
in this series, but maybe for the future.  There are a lot
of goto err_mbx_channel_Free in here already and this patch adds
another.  The cleanup there is trivial so DEFINE_FREE() and __free
usage will make this code quite a bit nicer to read.

> Signed-off-by: Huisong Li <lihuisong@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/soc/hisilicon/kunpeng_hccs.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/soc/hisilicon/kunpeng_hccs.c b/drivers/soc/hisilicon/kunpeng_hccs.c
> index 6e88f597f267..6055e5091cbd 100644
> --- a/drivers/soc/hisilicon/kunpeng_hccs.c
> +++ b/drivers/soc/hisilicon/kunpeng_hccs.c
> @@ -170,15 +170,21 @@ static int hccs_register_pcc_channel(struct hccs_dev *hdev)
>  		goto err_mbx_channel_free;
>  	}
>  
> -	if (pcc_chan->shmem_base_addr) {
> -		cl_info->pcc_comm_addr = ioremap(pcc_chan->shmem_base_addr,
> -						 pcc_chan->shmem_size);
> -		if (!cl_info->pcc_comm_addr) {
> -			dev_err(dev, "Failed to ioremap PCC communication region for channel-%u.\n",
> -				hdev->chan_id);
> -			rc = -ENOMEM;
> -			goto err_mbx_channel_free;
> -		}
> +	if (!pcc_chan->shmem_base_addr ||
> +	    pcc_chan->shmem_size != HCCS_PCC_SHARE_MEM_BYTES) {
> +		dev_err(dev, "The base address or size (%llu) of PCC communication region is invalid.\n",
> +			pcc_chan->shmem_size);
> +		rc = -EINVAL;
> +		goto err_mbx_channel_free;
Worth considering for the future: Maybe a DEFINE_FREE for pcc_mbox_free_channel) makes sense,
though if you do you should only assign cl_info->pcc_chan after all possible error paths.

> +	}
> +
> +	cl_info->pcc_comm_addr = ioremap(pcc_chan->shmem_base_addr,
> +					 pcc_chan->shmem_size);
> +	if (!cl_info->pcc_comm_addr) {
> +		dev_err(dev, "Failed to ioremap PCC communication region for channel-%u.\n",
> +			hdev->chan_id);
> +		rc = -ENOMEM;
> +		goto err_mbx_channel_free;
>  	}
>  
>  	return 0;



  reply	other threads:[~2024-08-23  8:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-18  7:11 [PATCH 0/5] Add some features and bugfix for kunpeng_hccs Huisong Li
2024-07-18  7:11 ` [PATCH 1/5] soc: hisilicon: kunpeng_hccs: fix a PCC typo Huisong Li
2024-07-18  7:11 ` [PATCH 2/5] soc: hisilicon: kunpeng_hccs: return failure on having not die or port information Huisong Li
2024-07-18  7:11 ` [PATCH 3/5] soc: hisilicon: kunpeng_hccs: add used HCCS type sysfs on platform Huisong Li
     [not found]   ` <66AB7194.1060404@hisilicon.com>
2024-08-09  4:07     ` lihuisong (C)
2024-07-18  7:11 ` [PATCH 4/5] soc: hisilicon: kunpeng_hccs: support low power feature for specified HCCS Huisong Li
2024-07-28 11:55   ` Krzysztof Kozlowski
2024-08-09  4:06     ` lihuisong (C)
2024-07-18  7:11 ` [PATCH 5/5] doc: soc: hisilicon: kunpeng_hccs: add low power interface description for HCCS Huisong Li
2024-08-23  3:10 ` [PATCH v2 0/6] Add some features and bugfix for kunpeng_hccs Huisong Li
2024-08-23  3:10   ` [PATCH v2 1/6] soc: hisilicon: kunpeng_hccs: Fix a PCC typo Huisong Li
2024-08-23  8:32     ` Jonathan Cameron
2024-08-23  3:10   ` [PATCH v2 2/6] soc: hisilicon: kunpeng_hccs: Return failure on having not die or port information Huisong Li
2024-08-23  8:33     ` Jonathan Cameron
2024-08-27 11:04       ` lihuisong (C)
2024-08-23  3:10   ` [PATCH v2 3/6] soc: hisilicon: kunpeng_hccs: Add the check for base address and size of shared memory Huisong Li
2024-08-23  8:38     ` Jonathan Cameron [this message]
2024-08-27 11:12       ` lihuisong (C)
2024-08-23  3:10   ` [PATCH v2 4/6] soc: hisilicon: kunpeng_hccs: Fix the 'lane_mode' field name in port info structure to 'max_lane_num' Huisong Li
2024-08-23  8:40     ` Jonathan Cameron
2024-08-27 11:15       ` lihuisong (C)
2024-08-23  3:10   ` [PATCH v2 5/6] soc: hisilicon: kunpeng_hccs: Add used HCCS types sysfs Huisong Li
2024-08-23  8:47     ` Jonathan Cameron
2024-08-27 11:32       ` lihuisong (C)
2024-08-23  3:10   ` [PATCH v2 6/6] soc: hisilicon: kunpeng_hccs: Support low power feature for the specified HCCS type Huisong Li
2024-08-23  8:58     ` Jonathan Cameron
2024-08-27 11:48       ` lihuisong (C)
2024-08-27 11:59         ` Jonathan Cameron
2024-08-23  9:02   ` [PATCH v2 0/6] Add some features and bugfix for kunpeng_hccs Jonathan Cameron
2024-08-27 11:49     ` lihuisong (C)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240823093858.00007047@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=krzk@kernel.org \
    --cc=lihuisong@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyonglong@huawei.com \
    --cc=soc@kernel.org \
    --cc=wanghuiqiang@huawei.com \
    --cc=xuwei5@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).