Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1540859ybk; Thu, 21 May 2020 09:14:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfslrrc2sgyvwEIGj6Sh4k1ayBq/BwKt5zVP/Gww1hhyjrSsbUp9jZph9XIe8Se72jPTd2 X-Received: by 2002:a05:6402:8c1:: with SMTP id d1mr8271354edz.265.1590077676185; Thu, 21 May 2020 09:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590077676; cv=none; d=google.com; s=arc-20160816; b=KyPeZYcHoFC9AfhS6o3Z7Ldsp7JbxwH8NSJuAkc95Uo8au37t1tphf6ubVFCGp3lJA kX/yXkpj9RYIn7ZzToIv92OIuo9Ikp2R8jxxOTpsP6RqjB/qIL1ELErG87UgsTeaYYUD H/oFewSr5XTJvPdJ18ud/CTI7L5KDrCn7JgXOuMltxM8XvjL69W2Z3va2mGfCE7aNw9o 7oAR1xxfIEl/1u8fZlXT/rm/sSYKn4VOmklneH8sqnLONyIyapt9HjE5N/P6KYX4VuES /j+2IKjX8ZxI52+IqI4wOy05dAJZnS8O1JkfxrD2hXBEYtB6JlS+ep0z1CxgOBhiXcwI i2NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:reply-to:message-id:date:subject:cc:to :from; bh=pVKzKEklQq37/ix/Mvyd5xQoSqlY88yXOzaPQGS/Zlw=; b=W4tZqw3fI06DYjlKSjSECDFFBVnqTKf8O9x6VfWREVAoqckfG9csgyd6tajRKofmuf BnbN6asZBAFIF5+6AVQglAj2uKdDJbJ1Bv93BvLwOhJ2t53J0GYMPWd5SUBkzY+Kl1y/ +IeiwoMzKTCkFWAN1jEieqj03sJ8iFUF+GDIEAPei8TpJu3+Hxjvm98vXXo+ZHE5hekI w0swu5nLG5fI3C8U6hdPYimXtCwbo7xd/ac3vvgixMDDFmGldn1izohslHYrtUioI9WU 2ETHOFDcRLqaphmwZvg491yWC050EWa/3OxjAwsBDnXeesRcR98SXtyCUuuTAiRAIfnT KLqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k5si3333817eds.231.2020.05.21.09.14.13; Thu, 21 May 2020 09:14:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729885AbgEUQMS (ORCPT + 99 others); Thu, 21 May 2020 12:12:18 -0400 Received: from inva021.nxp.com ([92.121.34.21]:54722 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729720AbgEUQMS (ORCPT ); Thu, 21 May 2020 12:12:18 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id D78FD2003E3; Thu, 21 May 2020 18:12:16 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id CBD862003E0; Thu, 21 May 2020 18:12:16 +0200 (CEST) Received: from fsr-ub1864-126.ea.freescale.net (fsr-ub1864-126.ea.freescale.net [10.171.82.212]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 76C2F20564; Thu, 21 May 2020 18:12:16 +0200 (CEST) From: Ioana Ciornei To: gregkh@linuxfoundation.org, laurentiu.tudor@nxp.com Cc: linux-kernel@vger.kernel.org, Ioana Ciornei Subject: [PATCH] bus: fsl-mc: allocate resources when there is no scan in progress Date: Thu, 21 May 2020 19:12:03 +0300 Message-Id: <20200521161203.10989-1-ioana.ciornei@nxp.com> X-Mailer: git-send-email 2.17.1 Reply-to: ioana.ciornei@nxp.com X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allocate resources from the fsl-mc bus only when a scan of the bus is not happening. This is useful when functional devices on the bus, such as DPNI, DPSW etc, request some kind of allocatable object but the scan of the bus is still in progress, thus those resources are not yet available. Catch this early and notify the upper layer driver of the condition. Signed-off-by: Ioana Ciornei --- drivers/bus/fsl-mc/fsl-mc-allocator.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c index cc7bb900f524..794ddc9589dc 100644 --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c @@ -184,6 +184,9 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, BUILD_BUG_ON(ARRAY_SIZE(fsl_mc_pool_type_strings) != FSL_MC_NUM_POOL_TYPES); + if (!mutex_trylock(&mc_bus->scan_mutex)) + return -ENXIO; + *new_resource = NULL; if (pool_type < 0 || pool_type >= FSL_MC_NUM_POOL_TYPES) goto out; @@ -197,7 +200,7 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, struct fsl_mc_resource, node); if (!resource) { - error = -ENXIO; + error = -ENOMEM; dev_err(&mc_bus_dev->dev, "No more resources of type %s left\n", fsl_mc_pool_type_strings[pool_type]); @@ -220,6 +223,7 @@ int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, mutex_unlock(&res_pool->mutex); *new_resource = resource; out: + mutex_unlock(&mc_bus->scan_mutex); return error; } EXPORT_SYMBOL_GPL(fsl_mc_resource_allocate); -- 2.17.1