Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1599210rdb; Mon, 8 Jan 2024 04:44:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgxRhvwED/Yqb/5aH8PVJmad3BXs5FXFg0ev090V0YI7gImLYX37wxqMUgdlqwU9b0q7dY X-Received: by 2002:a25:2611:0:b0:dbd:f0c7:891d with SMTP id m17-20020a252611000000b00dbdf0c7891dmr1107746ybm.19.1704717877623; Mon, 08 Jan 2024 04:44:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704717877; cv=none; d=google.com; s=arc-20160816; b=YfoRhNAC1yCtWQsxEAco2Xthb30wiZpwOOfxAJvlg9iS+6iknOwDh/UgAwYw8W2Jv8 P0xb3sgxzpFqEXDwBkjpFna1PTpBFCVyl/PkLa7iSlzf6YrP11J3934Fk+WFv8BcP2Yh /zHj58DJT7ZhI63YRi383MdeyQRSeFiXiyLtXsi1+eV/VUDA7CeGHEG8jQgJ4s0DsrHV jA1nmO02TZNGC9ixAGsZKunlmdN6Tr2RFej5UOujBhlj2cVyO9gxmameyPKOrPVnMXBx Zd/+RmgD/lpfOG0337vbzGnCuZNV35ecy+VwMG2Rx4LfKLUVKUDOsKzW19rChJnq1aLQ LpUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from; bh=ANbteUQBhExyoSug+rq+Hl3mfqOmQ1zr3Y+qTmR5r4I=; fh=yC+rbCZNfEFN2DLpTF2BdyYiHEbBGXmYn79WNneL20w=; b=XZ8/518JWPfVZ5vnE22E62ExhnkmjhvHNkWKpq4SpGS8zXzcUZSMB2kVJGUfqCqy/Q HqBy3RZvCcfO760kSEpWiX1+PmttXACj3ReQdz/nYIty5Xfj/XRZq8Xdetl+4bVItk9U Ql/aI79E3SRv2+gq1+HuwaX27LHsOoQluQebxrf7Q/qTKiqUtgJKNxZOxtneQhNUOLcZ zGPucbi8sNjnhfRiKhba7YbVPHLrTajFcyollno8YjxeUAF/4FZ4erSNfBhoqbRQk+pm KReK1wYKk1y9qp92grYsTP+6RmKqe6QHYere0sByEYRMtMzT7rwyJHkdXgUlH71TRiau xjpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19547-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19547-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p20-20020a05622a00d400b0042997fb63a8si1439934qtw.286.2024.01.08.04.44.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 04:44:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19547-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19547-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19547-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 58B9B1C20400 for ; Mon, 8 Jan 2024 12:44:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 384A055E4C; Mon, 8 Jan 2024 12:34:53 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F9FC4597F for ; Mon, 8 Jan 2024 12:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 95B3AC15; Mon, 8 Jan 2024 04:35:36 -0800 (PST) Received: from [127.0.1.1] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E13CE3F64C; Mon, 8 Jan 2024 04:34:49 -0800 (PST) From: Cristian Marussi Date: Mon, 08 Jan 2024 12:34:15 +0000 Subject: [PATCH 5/6] firmware: arm_ffa: Use xa_insert() and check for result Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240108-ffa_fixes_6-8-v1-5-75bf7035bc50@arm.com> References: <20240108-ffa_fixes_6-8-v1-0-75bf7035bc50@arm.com> In-Reply-To: <20240108-ffa_fixes_6-8-v1-0-75bf7035bc50@arm.com> To: Sudeep Holla Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Cristian Marussi X-Mailer: b4 0.12.4 While adding new partitions descriptors to the XArray the outcome of the stores should be checked and, in particular, it has also to be ensured that an existing entry with the same index was not already present, since partitions IDs are expected to be unique. Use xa_insert() instead of xa_store() since it returns -EBUSY when the index is already in use and log an error when that happens. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_ffa/driver.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 2426021dbb58..c613b57747cf 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -1197,7 +1197,7 @@ void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid) static void ffa_setup_partitions(void) { - int count, idx; + int count, idx, ret; uuid_t uuid; struct ffa_device *ffa_dev; struct ffa_dev_part_info *info; @@ -1236,7 +1236,14 @@ static void ffa_setup_partitions(void) continue; } rwlock_init(&info->rw_lock); - xa_store(&drv_info->partition_info, tpbuf->id, info, GFP_KERNEL); + ret = xa_insert(&drv_info->partition_info, tpbuf->id, + info, GFP_KERNEL); + if (ret) { + pr_err("%s: failed to save partition ID 0x%x - ret:%d\n", + __func__, tpbuf->id, ret); + ffa_device_unregister(ffa_dev); + kfree(info); + } } kfree(pbuf); @@ -1246,7 +1253,13 @@ static void ffa_setup_partitions(void) if (!info) return; rwlock_init(&info->rw_lock); - xa_store(&drv_info->partition_info, drv_info->vm_id, info, GFP_KERNEL); + ret = xa_insert(&drv_info->partition_info, drv_info->vm_id, + info, GFP_KERNEL); + if (ret) { + pr_err("%s: failed to save Host partition ID 0x%x - ret:%d. Abort.\n", + __func__, drv_info->vm_id, ret); + kfree(info); + } } static void ffa_partitions_cleanup(void) -- 2.34.1