Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp853472ybn; Tue, 24 Sep 2019 10:31:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOrBXgApIp8+8xv1vvbs1+VcFeguhRoF3PgLtHR2aPpGP6Z6IN/VK9xcWRZpYSUFVVXQ76 X-Received: by 2002:a17:906:e109:: with SMTP id gj9mr3587024ejb.160.1569346263992; Tue, 24 Sep 2019 10:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569346263; cv=none; d=google.com; s=arc-20160816; b=EUmDzrbkNzi2g+asLSdyt8EZm1L2lZPg5RcmVqvDpwv7y8/WsLCZ1C2Yc2P+WE+FX7 gariqJ2gWvm2Hwgljjiv4/ix0GFHTeJKyVpTJxIpFs6jT8PWYwyGVz7CRX0dUnTNfKp7 iGW5PWiATg+JWEO5tPJaMXQzwGCH1NnFWpkdTekQcsa6vrl/ewcWsOko0pZp1pRpjWpv WwAGst/CZwIoEfF4pl5j8yuBWKOez/oBP6qQg3NN1v+kW0PbaGBbbdWdrFUKmYD//BAz yVs/hfcSwPRdJqsSaxSr1ZycTPfe+uh/4Am9+hGrOBzPTy/ZDvTiuM8iBRC8zm5Vg0sJ V30g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=D1MqwgCYvbJu6IValUwEPFrYJOmBGkhRNlZvnEbWcYg=; b=oEFKe2BYEpPlITKW9sjMxRLdsucv6bav11+YcayTrP5IJREkb1hMWPlJsp+rrqu1kl vsMkkqGPHj1KbbrnqxDTmbcXaENirtb8w6K+apFPyLBG3DulMjFCur4FLWxxWA+Tpnh0 ud4PuTU7ByHKJzDaFWV/V9t3DxkdlGjIRSLAAuHNNhuBqjew2ZEsJpHFR6AYYcwFbjd8 KXJqtShkJY2lJ43gEbBXyIcXJCvQ5bliDugiIB5jt656HoeTzb+uea3+aHEkPVpPT/Ct cBmb4GX7EPXgQiOU2E7GwEfWIa+fKAJD/tkF2QA35nFHwdsZc2jWwu32fKqOmRH90foc WH4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@poorly.run header.s=google header.b=Zm3mOYaz; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fy7si1243932ejb.13.2019.09.24.10.30.37; Tue, 24 Sep 2019 10:31:03 -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=@poorly.run header.s=google header.b=Zm3mOYaz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730774AbfIWNkY (ORCPT + 99 others); Mon, 23 Sep 2019 09:40:24 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:45221 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbfIWNkY (ORCPT ); Mon, 23 Sep 2019 09:40:24 -0400 Received: by mail-yw1-f66.google.com with SMTP id x82so5184849ywd.12 for ; Mon, 23 Sep 2019 06:40:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=D1MqwgCYvbJu6IValUwEPFrYJOmBGkhRNlZvnEbWcYg=; b=Zm3mOYazo3XedQz6SPylC8Ylq9rfusxgBmYG5CjcLe9HBssqdZod3KYjsqQEc2SjSH VY9GjpK8SEfAaSiiM+UNtW9zAFktHUGsjkF61ejpHhEUsSkS+q30aTwpNOK8mWMT20G/ t38KbTxznENZbAls0bIDKUWw8Al+B8sV0+wOFQcQmJuqJFPPfZPXjbA581UW8rRNtbFV Y2yLgUnTU67vYXYcNlvFxrsoq+DnRk14/X2+HX0L9zMjrYow+mxgd3q/l0JtQHiocRRQ pz+eP4A0vfnFDAehD6vY9kNEgWFAU30VG70KWlKvjwy1eLsRnV+hvwBeGyAfQirPCtN6 +tmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=D1MqwgCYvbJu6IValUwEPFrYJOmBGkhRNlZvnEbWcYg=; b=pqqwoGnWEXF1zzlecRb/IgOnujlPWz1q93poS9KSssDU6dGENTRan8W3tuzSJs6J7t iNfMRYVKcikCn3Mw/x6+kXqnhsv/ZSFeel5aWRaXnGZbHDA+BNrT71ntCXeMLFEFsAte Qq9d9AJTuDnfUsZcHcVVjck5gDBywJY91D+uKLP8jBqKlabhZhy7KQ7rnvMISK02H1ya y2P3Cz0f/hkr+h73Okd8225FtAHcc6qSufdyCxy2wcdjK8EjUAQ8digW1IU30HtIbkFL ZpWtzvEqPDXYGBBYxppfY3rtWStqusHkYdtS35IsNqv27fbDfjdCOv26j2Nro1D55wo6 66jw== X-Gm-Message-State: APjAAAUhICxh3R8srK7JRg8fzv+tn7dCp9HLIQG9WSN+ZdWWhHn+LdJe qBS6CmpCcRWOzyaMFezb5YAlTA== X-Received: by 2002:a0d:d891:: with SMTP id a139mr22398928ywe.52.1569246023080; Mon, 23 Sep 2019 06:40:23 -0700 (PDT) Received: from localhost ([2620:0:1013:11:89c6:2139:5435:371d]) by smtp.gmail.com with ESMTPSA id v62sm2589761ywc.105.2019.09.23.06.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 06:40:22 -0700 (PDT) Date: Mon, 23 Sep 2019 09:40:22 -0400 From: Sean Paul To: Gerd Hoffmann Cc: dri-devel@lists.freedesktop.org, seanpaul@chromium.org, jani.nikula@linux.intel.com, Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , open list Subject: Re: [PATCH v2] drm: tweak drm_print_bits() Message-ID: <20190923134022.GZ218215@art_vandelay> References: <20190923065814.4797-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190923065814.4797-1-kraxel@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 23, 2019 at 08:58:14AM +0200, Gerd Hoffmann wrote: > There is little reason for the from/to logic, printing a subset of > the bits can be done by simply shifting/masking value if needed. > > Also use for_each_set_bit(). > > Suggested-by: Jani Nikula > Signed-off-by: Gerd Hoffmann > Reviewed-by: Jani Nikula Acked-by: Sean Paul > --- > include/drm/drm_print.h | 5 ++--- > drivers/gpu/drm/drm_gem_ttm_helper.c | 4 ++-- > drivers/gpu/drm/drm_print.c | 20 +++++++++----------- > 3 files changed, 13 insertions(+), 16 deletions(-) > > diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h > index 12d4916254b4..89d38d07316c 100644 > --- a/include/drm/drm_print.h > +++ b/include/drm/drm_print.h > @@ -89,9 +89,8 @@ __printf(2, 3) > void drm_printf(struct drm_printer *p, const char *f, ...); > void drm_puts(struct drm_printer *p, const char *str); > void drm_print_regset32(struct drm_printer *p, struct debugfs_regset32 *regset); > -void drm_print_bits(struct drm_printer *p, > - unsigned long value, const char *bits[], > - unsigned int from, unsigned int to); > +void drm_print_bits(struct drm_printer *p, unsigned long value, > + const char * const bits[], unsigned int nbits); > > __printf(2, 0) > /** > diff --git a/drivers/gpu/drm/drm_gem_ttm_helper.c b/drivers/gpu/drm/drm_gem_ttm_helper.c > index 9a4bafcf20df..a534104d8bee 100644 > --- a/drivers/gpu/drm/drm_gem_ttm_helper.c > +++ b/drivers/gpu/drm/drm_gem_ttm_helper.c > @@ -23,7 +23,7 @@ > void drm_gem_ttm_print_info(struct drm_printer *p, unsigned int indent, > const struct drm_gem_object *gem) > { > - static const char const *plname[] = { > + static const char * const plname[] = { > [ TTM_PL_SYSTEM ] = "system", > [ TTM_PL_TT ] = "tt", > [ TTM_PL_VRAM ] = "vram", > @@ -40,7 +40,7 @@ void drm_gem_ttm_print_info(struct drm_printer *p, unsigned int indent, > const struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem); > > drm_printf_indent(p, indent, "placement="); > - drm_print_bits(p, bo->mem.placement, plname, 0, ARRAY_SIZE(plname)); > + drm_print_bits(p, bo->mem.placement, plname, ARRAY_SIZE(plname)); > drm_printf(p, "\n"); > > if (bo->mem.bus.is_iomem) { > diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c > index dfa27367ebb8..52cc7b38eb12 100644 > --- a/drivers/gpu/drm/drm_print.c > +++ b/drivers/gpu/drm/drm_print.c > @@ -189,28 +189,26 @@ EXPORT_SYMBOL(drm_printf); > * drm_print_bits - print bits to a &drm_printer stream > * > * Print bits (in flag fields for example) in human readable form. > - * The first name in the @bits array is for the bit indexed by @from. > * > * @p: the &drm_printer > * @value: field value. > * @bits: Array with bit names. > - * @from: start of bit range to print (inclusive). > - * @to: end of bit range to print (exclusive). > + * @nbits: Size of bit names array. > */ > -void drm_print_bits(struct drm_printer *p, > - unsigned long value, const char *bits[], > - unsigned int from, unsigned int to) > +void drm_print_bits(struct drm_printer *p, unsigned long value, > + const char * const bits[], unsigned int nbits) > { > bool first = true; > unsigned int i; > > - for (i = from; i < to; i++) { > - if (!(value & (1 << i))) > - continue; > - if (WARN_ON_ONCE(!bits[i-from])) > + if (WARN_ON_ONCE(nbits > BITS_PER_TYPE(value))) > + nbits = BITS_PER_TYPE(value); > + > + for_each_set_bit(i, &value, nbits) { > + if (WARN_ON_ONCE(!bits[i])) > continue; > drm_printf(p, "%s%s", first ? "" : ",", > - bits[i-from]); > + bits[i]); > first = false; > } > if (first) > -- > 2.18.1 > -- Sean Paul, Software Engineer, Google / Chromium OS