Received: by 10.213.65.68 with SMTP id h4csp85534imn; Mon, 26 Mar 2018 15:47:47 -0700 (PDT) X-Google-Smtp-Source: AG47ELuLpZCZOfz8g4CDl6kZR2/inzX5+HTMG9kfTYzNYo7GIqdft2t6vDdeOZOLOeM3p/bhp806 X-Received: by 10.101.76.129 with SMTP id m1mr16606105pgt.90.1522104466999; Mon, 26 Mar 2018 15:47:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522104466; cv=none; d=google.com; s=arc-20160816; b=Q6QnxCVRbriTYDhyDJxtaZJaLuX4vbrMLZSJT17CIp2gvqJdFysbYsiMmxfkNQU3b5 zzQJiHfHe+0WtKcbrJ6RfCLxMzluu35SUv3S3iSyyTUD/E04VdRJ5k1q1vgY65uDhopO VlpjUWFop3OTtjvGZNCcTMfpBYTimCxq8RDiN8GCOfEy4DuOez0CuqIpdfY7+6EbkF+T E5YGGYaUAVcTGv4DDA5rVQFsH466eLGMJ8/sQr1A4v1hdu34Qaj10yTczywW3DmtWWBf Co+tgA85KH6Ms4e0noPYrS7CbX3BogPao7TJwdO6hULGRZm8/0qw1T73QoxomIXW4X3O kNSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=6d+/1AEjYz2A21M5YmURWoC6LJHlPKR6n6lIKKkVQPY=; b=N/objCgb1RhVGbvGlqlFuEP8QagVsvrq9idtsBNXu1eYiWETEjfa88Lug1IJmGz2R7 B8nmOjQlOkbT4vt2OL+sn1ZBT+DAndL1YePdhK9V9GJPxifHU49OGvvtW10k8oMkYkdx rs4HYb6fqphOe4BW4doULTpHvpDq+1H6UZtH+zNDYb/XBCApy9TEDdVAHKMwLLnaJv3u 3DKqAkzA8faG0n0xXfY+oPzAXL4T5npp3Cx+7OSUh/gueaipMhzU+2FaDqzHs+h4pPrZ 6gqJfC5pv84TFYsdak2CjbSFEQXv3e2amPzglDkuR06OaL//MP+sdONyxlh/ts47xRPp zn0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QhAtjiWz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5-v6si14896210plp.20.2018.03.26.15.47.32; Mon, 26 Mar 2018 15:47:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QhAtjiWz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752563AbeCZWqR (ORCPT + 99 others); Mon, 26 Mar 2018 18:46:17 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:46006 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752157AbeCZWqQ (ORCPT ); Mon, 26 Mar 2018 18:46:16 -0400 Received: by mail-pg0-f67.google.com with SMTP id y63so4704735pgy.12 for ; Mon, 26 Mar 2018 15:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=6d+/1AEjYz2A21M5YmURWoC6LJHlPKR6n6lIKKkVQPY=; b=QhAtjiWzJcWvfeMffPrhrNRPf9rQpEukBV+ErCLqYB5H2CdsXHvStC83CC7c2uVGt+ 0FFUJvoTz16XDBqcAzU1w4c/EGSETgBsAun82hPH2HEnN1rAhL0asRhxmSaKsdc0oDSu blNfkhLcY2f33dUq5ZjLgF0R3Zn5PIgGa3+1N8rXm31cmKF6LKJy1QW/L+FUprqY8ujS nrt/VHYDuyPPty67vjJfWSeMlgs4bQDfPL1CSbo+Yvrv/uo+zYCDY3VTt/vk5U9tXugE g6EmEFHJfMhHrtJyZepiAp7abEj1JBwGZiYSefnESF96SNPWjbDgD0SbEyoKD3wuGWz3 GiOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6d+/1AEjYz2A21M5YmURWoC6LJHlPKR6n6lIKKkVQPY=; b=Muv78RwqC/H60hXe5TXZF+iPr5uktBFwoASw8Fi6vL6tRuu8WL5UIkvpb3jdinGaTT y0HI6wrbNUDbMmWJ64FBfv5vAwEPfPa4fqNBWAOLyjv4tMuMfKgYfQryUrDPFtQuhNBB WEe5fk5Mngh3E7KsdqrqwISIhqY7ChbZMaOX4iocmitbZvYGrOof0Z989pnMZHDh5BD6 OLlac/S+bbnjeg057FMZqoaCJCU3Sho2A0lKHyJwFHCzSMPKV6sIrkt5XX6zqpKP5X/b HEOo0KCHy3JJRYBUnzQWsYanprJ9mFMz8u32vc1NnPaCHQQMC2DiUeQYD/SSSRlOI5wB l2xg== X-Gm-Message-State: AElRT7FbuvK9bDYS/xHy8pVY6hAydR6nINDx+cBxjj/c2agGn+lSTbcQ i+z2clgTmz1F6BKsfpXvC2M= X-Received: by 10.99.107.6 with SMTP id g6mr30192904pgc.109.1522104376250; Mon, 26 Mar 2018 15:46:16 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id p89sm15650441pfk.63.2018.03.26.15.46.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 15:46:15 -0700 (PDT) From: Wei Yang To: vgoyal@redhat.com, thomas.lendacky@amd.com, bp@suse.de Cc: linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH] kernel/resource: refine find_next_iomem_res() a little Date: Tue, 27 Mar 2018 06:46:06 +0800 Message-Id: <20180326224606.79666-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.15.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch does several refine for find_next_iomem_res() * use first_level_children_only directly * remove some local variables * use resrouce_clip() Signed-off-by: Wei Yang --- kernel/resource.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index e270b5048988..769109f20fb7 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -351,6 +351,15 @@ int release_resource(struct resource *old) EXPORT_SYMBOL(release_resource); +static void resource_clip(struct resource *res, resource_size_t min, + resource_size_t max) +{ + if (res->start < min) + res->start = min; + if (res->end > max) + res->end = max; +} + /* * Finds the lowest iomem resource existing within [res->start.res->end). * The caller must specify res->start, res->end, res->flags, and optionally @@ -361,31 +370,24 @@ EXPORT_SYMBOL(release_resource); static int find_next_iomem_res(struct resource *res, unsigned long desc, bool first_level_children_only) { - resource_size_t start, end; struct resource *p; - bool sibling_only = false; BUG_ON(!res); - - start = res->start; - end = res->end; - BUG_ON(start >= end); - - if (first_level_children_only) - sibling_only = true; + BUG_ON(res->start >= res->end); read_lock(&resource_lock); - for (p = iomem_resource.child; p; p = next_resource(p, sibling_only)) { + for (p = iomem_resource.child; p; + p = next_resource(p, first_level_children_only)) { if ((p->flags & res->flags) != res->flags) continue; if ((desc != IORES_DESC_NONE) && (desc != p->desc)) continue; - if (p->start > end) { + if (p->start > res->end) { p = NULL; break; } - if ((p->end >= start) && (p->start < end)) + if ((p->end >= res->start) && (p->start < res->end)) break; } @@ -393,10 +395,7 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc, if (!p) return -1; /* copy data */ - if (res->start < p->start) - res->start = p->start; - if (res->end > p->end) - res->end = p->end; + resource_clip(res, p->start, p->end); res->flags = p->flags; res->desc = p->desc; return 0; @@ -600,15 +599,6 @@ static resource_size_t simple_align_resource(void *data, return avail->start; } -static void resource_clip(struct resource *res, resource_size_t min, - resource_size_t max) -{ - if (res->start < min) - res->start = min; - if (res->end > max) - res->end = max; -} - /* * Find empty slot in the resource tree with the given range and * alignment constraints -- 2.15.1