Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp239557lqp; Mon, 10 Jun 2024 02:32:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU6Oc0U/EoML146RRb3eIlQBJ2h6sH289aOVB7PgoxhysE+dLilve3eaIMvVtQ1LX5Rp/43fFdC3j1jJRF/v97CoMbPi+5YgHFokd1cMg== X-Google-Smtp-Source: AGHT+IEOuARWoWsklOWzgxHOmc8LceFVpn7GZyJRxXZa0BLnZ2EhDg/7LLqRHr4DbzhLdY5U/WSZ X-Received: by 2002:a17:906:54c8:b0:a6f:1445:9de5 with SMTP id a640c23a62f3a-a6f1445f010mr213301666b.68.1718011948168; Mon, 10 Jun 2024 02:32:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718011948; cv=pass; d=google.com; s=arc-20160816; b=zyEAq8VFdvF3SY2NLTt0pfkWM3iRYJjmx0lNsnmbzUVzWdwoc7jpUN5o3Y/N2Dotd/ HWmZ1JCkrDYpCo2r1/xzjbVfOvXlltaXqAV9BzpvFhzX42IpJolNtcd2FTZbHcOqknu1 w7hsw0wL608SUwKguzGbI/JDWswoDUL9QpaDOZ525/kRgM0YVF2E8I2v9w1N0oI+WChJ 2NlTTHxF/x4l08Ig0gc4I0REMwah8lLBMR792RHOc4m4/ZVKjf4ikP6sQloTLynzvOQD /munvcmkvRDWjMUp9zKNz6DbGgsC8L6ZV/gjliM7qzwU/+eo8lloXtvBzeDzW+dBN9Eg /2oA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Oyizp71aDVZTVSj1hEgGPWD4Zgvxaje3MhAhMHAAQDo=; fh=71VAejVXvSjsvQDHZWOVaDAr1bmICqKU3xpyRFYFm/M=; b=hnZlUJT7Ts+7g8icoyo+qGN6dGDmwkRcMTOgszweMD/Xqm3chfMcGZb5cLQ9CRpOCv XtgnPjac/i81dSLUHpB0Gp8GIQvkHI1gUlz9lheeB7f/BRCL8xA3HFNsHCkVHoUjj4ya SohErDRMf5Y43U06p3ZLNXAqHZAMEZXMeI5YOB+865FN/N+73nA72c77B7eS9wbUrIqW uee7H3gK0W+1nAgKfpKQ7PXmd7+IR0gHv9IWsMx27vrbk8LQqQJPY7D3hqQHra/xVifG dqiz9uFEwMntvf5FOS2K4h8tM1rudyS1UKj3xXm6ds2lm6foZ0mzWup2DsMM7J7ndspI gOyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bjAjzY4d; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-207940-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207940-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f2f637ebasi3731366b.675.2024.06.10.02.32.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 02:32:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207940-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bjAjzY4d; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-207940-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207940-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 am.mirrors.kernel.org (Postfix) with ESMTPS id DAE341F23AE6 for ; Mon, 10 Jun 2024 09:32:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD99E762DF; Mon, 10 Jun 2024 09:32:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bjAjzY4d" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 4EED2745F4 for ; Mon, 10 Jun 2024 09:32:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718011927; cv=none; b=D0ejyE3FmJzvNYSVAw3IzpZQXtSTNDyESnEL7U8u9Oa4bbEIYvTLGiJdlKda4Yf6EWacz79VOOk5uQa+IGM8KBDfx+Ip0uPajbyoOgC174KOW+sSYa53qIHx/vQlMlQ5aIVxC/9IvWWPafpVmDDctNrk44JSIU6pQm/M+VrBERw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718011927; c=relaxed/simple; bh=uxWR+cyvQnS6F+Ku7i7pYs3ZA+OagBoxvbut16jkiT8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dTUnFdtUsAWVUokmKMBsWb0UfRjW5xKa+FgsVpkxfecw+EumRAcqMum1Fv8lhkw+d7kX5+Ff5vsn+4DcfWP1QinaWOvBeESheCm285mAjuDgnWm+SRQdkwZ6aID0zjiXflP/bbU05awVnMZKJaK6CTXtntq9PnrHjqWtQ1jAigA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bjAjzY4d; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718011925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Oyizp71aDVZTVSj1hEgGPWD4Zgvxaje3MhAhMHAAQDo=; b=bjAjzY4dZQ04UhdkOLzNLGH6i7y/hSEUK/b9wpeeeBKmNcA0GviTq3a0pEDm31G+5q27lZ W4RvMcDPnSi23LgKCne3ZHuHCAo4WS82SkvOSNs0F/Hw6ywvuMDgtVdjXkkiR+xyO3SoF6 yIcRLI3NJbgzaFulQDN4gJUgySwpqvA= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-XeSfhOfXOhiqCldYe3d3Xg-1; Mon, 10 Jun 2024 05:32:02 -0400 X-MC-Unique: XeSfhOfXOhiqCldYe3d3Xg-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4215f69475cso3516505e9.3 for ; Mon, 10 Jun 2024 02:32:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718011921; x=1718616721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oyizp71aDVZTVSj1hEgGPWD4Zgvxaje3MhAhMHAAQDo=; b=o7TIt4yvTdaEEmBNiiNSu3upEPluLOCiO2kgWuoMq91/dNmeeJ2xJImq9d6R+QLOrM PwYX/i6znPKwTtDgtf61HsuV0GUkk/qhk7R7P9BEXV6xFZljLYu+kRwjT+s0CEmJSBco dP6rmBLbmRBatW3Az/fKL2gc567OqWdHORF704NxXXMI0rEulItjHL4RPwBLhmNzYShn 8dEbzBKUDh6UUxH1QhKxqwtA5BLkxDrB6TmGSWiU3Tkf0ui+lGPbJY8g3HgBRxGFG4aQ DNubH81YY4UkVdE+dKYv9Hn1qimyOX58ipSy7Ys0+os+VGgaBGyn81yvHI8yAARqbNvc 20FA== X-Forwarded-Encrypted: i=1; AJvYcCX2H7v5/UDGFx/t5BkYDTiDOs/wr3rw7oqJacGWpi9PawCIEagiqY8m7DtGiPrAKqFyWNDFzqAaM0IeGtrwq6TQe65oe/BU8169E+SJ X-Gm-Message-State: AOJu0YyVS40OGTZAxWTaqEkUIK1i25Ukc8DbdoxbcXtlE1fUhIRpJEN6 LMJ8E+muEVWpBZQKhyi2yOM3eIMv5PhDPrrhtFnf7meIWEUCKoPT9z2lyg15nVqOsruDpq0bhuE oVNBuiifDeNdV1QcCV2uKar34p53d9FGvPpjqtAt2g7u1i2o3g63r+KG/ZvvAMg== X-Received: by 2002:a5d:64cb:0:b0:354:e778:3665 with SMTP id ffacd0b85a97d-35efee307bamr7423570f8f.5.1718011920873; Mon, 10 Jun 2024 02:32:00 -0700 (PDT) X-Received: by 2002:a5d:64cb:0:b0:354:e778:3665 with SMTP id ffacd0b85a97d-35efee307bamr7423555f8f.5.1718011920534; Mon, 10 Jun 2024 02:32:00 -0700 (PDT) Received: from pstanner-thinkpadt14sgen1.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35f0ce4b62fsm7257545f8f.80.2024.06.10.02.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 02:32:00 -0700 (PDT) From: Philipp Stanner To: Hans de Goede , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Bjorn Helgaas , Sam Ravnborg , dakr@redhat.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Philipp Stanner Subject: [PATCH v8 01/13] PCI: Add and use devres helper for bit masks Date: Mon, 10 Jun 2024 11:31:23 +0200 Message-ID: <20240610093149.20640-2-pstanner@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240610093149.20640-1-pstanner@redhat.com> References: <20240610093149.20640-1-pstanner@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The current derves implementation uses manual shift operations to check whether a bit in a mask is set. The code can be made more readable by writing a small helper function for that. Implement mask_contains_bar() and use it where applicable. Link: https://lore.kernel.org/r/20240605081605.18769-3-pstanner@redhat.com Signed-off-by: Philipp Stanner Signed-off-by: Bjorn Helgaas --- drivers/pci/devres.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c index 2c562b9eaf80..f13edd4a3873 100644 --- a/drivers/pci/devres.c +++ b/drivers/pci/devres.c @@ -161,6 +161,10 @@ int pcim_set_mwi(struct pci_dev *dev) } EXPORT_SYMBOL(pcim_set_mwi); +static inline bool mask_contains_bar(int mask, int bar) +{ + return mask & BIT(bar); +} static void pcim_release(struct device *gendev, void *res) { @@ -169,7 +173,7 @@ static void pcim_release(struct device *gendev, void *res) int i; for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) - if (this->region_mask & (1 << i)) + if (mask_contains_bar(this->region_mask, i)) pci_release_region(dev, i); if (this->mwi) @@ -363,7 +367,7 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name) for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { unsigned long len; - if (!(mask & (1 << i))) + if (!mask_contains_bar(mask, i)) continue; rc = -EINVAL; @@ -386,7 +390,7 @@ int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name) pci_release_region(pdev, i); err_inval: while (--i >= 0) { - if (!(mask & (1 << i))) + if (!mask_contains_bar(mask, i)) continue; pcim_iounmap(pdev, iomap[i]); pci_release_region(pdev, i); @@ -438,7 +442,7 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask) return; for (i = 0; i < PCIM_IOMAP_MAX; i++) { - if (!(mask & (1 << i))) + if (!mask_contains_bar(mask, i)) continue; pcim_iounmap(pdev, iomap[i]); -- 2.45.0