Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8195443ybi; Tue, 23 Jul 2019 04:29:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYrKbs9N0+RE5cGHxIVLqeP+blWMVMSMglJ207h8R7WWwS2RSjueTHCNvhlkA6BgiaMjKV X-Received: by 2002:a17:902:744c:: with SMTP id e12mr79666598plt.287.1563881371276; Tue, 23 Jul 2019 04:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563881371; cv=none; d=google.com; s=arc-20160816; b=PkHrAbHAjuYyfELOr4Q8hHRvKmH8qYICViiRz2DvefbyrDl1wXJhILrd5QwlZPd/Jx NS2ukwpC9nGlDjp9DZQWseAHRt/dnqVsrniSsxcVv1mIY0bA2JHxef34sLCjpEOIBFDf OC0O92Gnt67URhJBBcJ4Dg6JontA2xM/7DEgUz0mVcwhKYoyA9ZclQfBld/8K9x3DZy5 C0FVHjQGMIwOPsKeaKZ+LXljBkN5wGGr7qwAoTiKf5r3tPAoEMY+htyNsy4bKnzx9NA4 +7U52emu9R7ZI1Lf/P4Pwr4aTEC4WYWqqQwguajSo1LlUE5kolIoPPCoLOCyia+Rg5SF rQIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:user-agent:from:cc:to:subject :references:in-reply-to:content-transfer-encoding:mime-version :message-id:dkim-signature; bh=uoHZGPhy7AaMBBkhIfbi+3coowHMdF6umFxF94wcksg=; b=YTz5DBphClGspoE4nG1PyeytMvQlcv7PN9m8e7oprrvXU0ACqynHXZrxLpmDfvoig7 YWRlk6Sha3hVLZsg5GB+b+4lPb+QoWl6t6mghpf2HzsyhsmUqgp79gOEIYgSwy79rGgI zXA7JvrbNxjP+sNdAj6i1SgPEyLVZOEWgIAtH3L/qsDJYqqYbzQnrc0ZRolMP0F6yXe8 2gvyc5FGeZ00OG7rQkRzoFN4wPeKoT2h442XqX3fVmC7oVSAph4aIetHv5XaowFk4Xv7 4ko6HlYB2YqiIwkyIl6WRpZ6oiFFe/WhSHAqrV0+gDUZ4UsIQjtGLSyKe8W8k06Q516p uPvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VgLgZhkE; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68si13023818pgb.104.2019.07.23.04.28.41; Tue, 23 Jul 2019 04:29:31 -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=@chromium.org header.s=google header.b=VgLgZhkE; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387577AbfGWAFA (ORCPT + 99 others); Mon, 22 Jul 2019 20:05:00 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33711 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727172AbfGWAFA (ORCPT ); Mon, 22 Jul 2019 20:05:00 -0400 Received: by mail-pl1-f193.google.com with SMTP id c14so19783139plo.0 for ; Mon, 22 Jul 2019 17:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=message-id:mime-version:content-transfer-encoding:in-reply-to :references:subject:to:cc:from:user-agent:date; bh=uoHZGPhy7AaMBBkhIfbi+3coowHMdF6umFxF94wcksg=; b=VgLgZhkEw8c6bGaz8lCXFux+cen+0GeTncyzKcaz4eOQUkOCuYdm1vzo16ayzWEfFH SHHI1FmMYtbVCh78rrfbsteiwlxOg1o6N1Z3aRpjghlOjBWowZ38LG6oUU0g+HI0YBZv sAbfVWkDIvYzhymezHOXRGayAwrp6CO/wsc6o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:mime-version :content-transfer-encoding:in-reply-to:references:subject:to:cc:from :user-agent:date; bh=uoHZGPhy7AaMBBkhIfbi+3coowHMdF6umFxF94wcksg=; b=YuckWst9jxHASHeCX/AndkgnuZAiY1SViCPKtbVXa7DpzF+d2Cf2BRfHZZ4X5ERWZl +t/IV+xxsL/31VSSM/OSnObQiMme87Gdrve4yF+BPu9wTjqzrc7RjhT3+Yk5pEPo0zG8 lAYrouVldlc5Av7LZ5nD1iysiu5ImbnAFcuNphhWfatJrllu5Z99DieAqu26uOCsqH7o wqKARktYfYbg5yptoF2UzkNgjSHi395weOaDnXx44xN7JjjWxFGEBVYa9iNcTSXkrVnr WDN+9wI9JxS6/sZhJth7q6tvPLb54wTnaJ0t9xfQskcoaKY3PGUrCwY2HPKlbORqgJbM 2Xig== X-Gm-Message-State: APjAAAX6oJthuTPzhNC/X5S+aNQJxliloAZzp47+ZjhRkuwctsFBBKsP nggReeTQTUOhGQhmbNeXUGALcA== X-Received: by 2002:a17:902:1101:: with SMTP id d1mr33344225pla.212.1563840299152; Mon, 22 Jul 2019 17:04:59 -0700 (PDT) Received: from chromium.org ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id k64sm21699923pge.65.2019.07.22.17.04.58 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 22 Jul 2019 17:04:58 -0700 (PDT) Message-ID: <5d364f2a.1c69fb81.e3ed.7bfd@mx.google.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20190722232719.GT30636@minitux> References: <23774.56553.445601.436491@mariner.uk.xensource.com> <20190517210923.202131-3-swboyd@chromium.org> <20190722232719.GT30636@minitux> Subject: Re: [PATCH 2/3] firmware: qcom_scm: Cleanup code in qcom_scm_assign_mem() To: Bjorn Andersson Cc: Andy Gross , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Ian Jackson , Julien Grall , Avaneesh Kumar Dwivedi From: Stephen Boyd User-Agent: alot/0.8.1 Date: Mon, 22 Jul 2019 17:04:57 -0700 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Bjorn Andersson (2019-07-22 16:27:19) > On Fri 17 May 14:09 PDT 2019, Stephen Boyd wrote: >=20 > > There are some questionable coding styles in this function. It looks > > quite odd to deref a pointer with array indexing that only uses the > > first element. Also, destroying an input/output variable halfway through > > the function and then overwriting it on success is not clear. It's > > better to use a local variable and the kernel macros to step through > > each bit set in a bitmask and clearly show where outputs are set. > >=20 > > Cc: Ian Jackson > > Cc: Julien Grall > > Cc: Bjorn Andersson > > Cc: Avaneesh Kumar Dwivedi > > Signed-off-by: Stephen Boyd > > --- > > drivers/firmware/qcom_scm.c | 34 ++++++++++++++++------------------ > > include/linux/qcom_scm.h | 9 +++++---- > > 2 files changed, 21 insertions(+), 22 deletions(-) > >=20 > > diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c > > index 0c63495cf269..153f13f72bac 100644 > > --- a/drivers/firmware/qcom_scm.c > > +++ b/drivers/firmware/qcom_scm.c > > @@ -443,7 +443,8 @@ EXPORT_SYMBOL(qcom_scm_set_remote_state); > > */ > > int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, > > unsigned int *srcvm, > > - struct qcom_scm_vmperm *newvm, int dest_cnt) > > + const struct qcom_scm_vmperm *newvm, > > + unsigned int dest_cnt) > > { > > struct qcom_scm_current_perm_info *destvm; > > struct qcom_scm_mem_map_info *mem_to_map; > > @@ -458,11 +459,10 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, siz= e_t mem_sz, > > int next_vm; > > __le32 *src; > > void *ptr; > > - int ret; > > - int len; > > - int i; > > + int ret, i, b; > > + unsigned long srcvm_bits =3D *srcvm; > > =20 > > - src_sz =3D hweight_long(*srcvm) * sizeof(*src); > > + src_sz =3D hweight_long(srcvm_bits) * sizeof(*src); > > mem_to_map_sz =3D sizeof(*mem_to_map); > > dest_sz =3D dest_cnt * sizeof(*destvm); > > ptr_sz =3D ALIGN(src_sz, SZ_64) + ALIGN(mem_to_map_sz, SZ_64) + > > @@ -475,28 +475,26 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, siz= e_t mem_sz, > > =20 > > /* Fill source vmid detail */ > > src =3D ptr; > > - len =3D hweight_long(*srcvm); > > - for (i =3D 0; i < len; i++) { > > - src[i] =3D cpu_to_le32(ffs(*srcvm) - 1); > > - *srcvm ^=3D 1 << (ffs(*srcvm) - 1); > > - } > > + i =3D 0; > > + for_each_set_bit(b, &srcvm_bits, sizeof(srcvm_bits)) >=20 > The modem is sad that you only pass 8 here. Changed it to BITS_PER_LONG > to include the modem's permission bit and applied all three patches. >=20 Ah of course. Thanks. BTW, srcvm is an unsigned int, but then we do a bunch of unsigned long operations on them. Maybe the whole API should be changed to be more explicit about the size of the type, i.e. u64?