Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2393663ybh; Mon, 9 Mar 2020 05:06:38 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv+SfyzPivBEx6aIFbHY8w7W1WZ7lcLEOKS7l3jGWyoY2Gw/eiW+z4IW4dkU4FpFrzgh0sS X-Received: by 2002:a05:6808:b30:: with SMTP id t16mr1891059oij.117.1583755598852; Mon, 09 Mar 2020 05:06:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583755598; cv=none; d=google.com; s=arc-20160816; b=DT3D0slMyTnrLMR4BibdFP4VPkqw4nCwrpsUuxSOhzv2YvgcKQxV9OEi9bKqFcWw+N OKtx3gcYEqYMukvFJo86alpU/fUOZySi2xO6p89Fp+V/h+Xt9JNzy4CU6N/E103Y3cLO 5aFSUF8c9ZXToQbnmtQgZbt2MSvUWbHCwhFDXh7mWHMDt2n4wyzVv3NfLfsLGYA+S1AP RZXpUXw3vqj1ZQ60Eqd7fac99UWxdcdb1mACuieizzfxyCifgy+we7Y16IK752yaeRuu ySWg/YD0KQDnK1Aql3ro5Row76NxRrNMdf83/P/6TLUBKSalc3aqyUctwtXJuSonAf/O aypg== 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; bh=pSARS+vSrix7jKa8vFaLW7fusskjMcZNIPEXc8aZfKo=; b=uXZRmyUUvBq44aAFOljwUzFQwnobIKID0icXPMENFmCxcgvNZZ5yOPVH9oRraughsd gFE0WgyOJMgWjnuWyI7+QzryKhwsUG3y0D/FsNv61ObKRneKuIuo4VlxUu0D7eQaEyrX zpAhmud0ofM1w7P5Am8RRI1JN2NUSGV8SCYxK2P2Ue3PaoVR7kQdSCvzRpX8haAZ0DRp Gu0KEsTZOACnrBVBVl8roSzePJJNFXbJjWd401AGcQKpe7AZh015F/sXfBNB1z9jBONA gDbEhuAVGPz7N+n1gvU9hbxRzjTmXS1YJthS1u7/snm2HQZ9vl/8vrVFhR1kmE5dpWnK dJFw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si3454980oix.239.2020.03.09.05.06.25; Mon, 09 Mar 2020 05:06:38 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726450AbgCIMFp (ORCPT + 99 others); Mon, 9 Mar 2020 08:05:45 -0400 Received: from foss.arm.com ([217.140.110.172]:51210 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbgCIMFp (ORCPT ); Mon, 9 Mar 2020 08:05:45 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6798B30E; Mon, 9 Mar 2020 05:05:44 -0700 (PDT) Received: from localhost (unknown [10.37.6.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E05483F6CF; Mon, 9 Mar 2020 05:05:43 -0700 (PDT) Date: Mon, 9 Mar 2020 12:05:42 +0000 From: Mark Brown To: peng.fan@nxp.com Cc: gregkh@linuxfoundation.org, rafael@kernel.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] regmap: debugfs: check count when read regmap file Message-ID: <20200309120542.GC4101@sirena.org.uk> References: <1583673058-20531-1-git-send-email-peng.fan@nxp.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="GPJrCs/72TxItFYR" Content-Disposition: inline In-Reply-To: <1583673058-20531-1-git-send-email-peng.fan@nxp.com> X-Cookie: Above all things, reverence yourself. 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 --GPJrCs/72TxItFYR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Mar 08, 2020 at 09:10:58PM +0800, peng.fan@nxp.com wrote: > From: Peng Fan > @@ -283,9 +283,10 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf, > size_t count, loff_t *ppos) > { > struct regmap *map = file->private_data; > + size_t num = count > map->max_register ? map->max_register : count; I can see that it might be useful to limit the read size (though our error checking is doing the right thing here, it's just that kmalloc() is very verbose) but this doesn't seem like a good limit, especially for smaller register maps. Since it's limiting reads to the number of registers it's going to result in it being impossible to dump the full register map in a single read. This is fine from a filesystem API point of view, reads can always return less data than was asked for, but it's annoying from the point of view of anyone hacking together something like a little program to monitor a specific register during testing or whatever. If the register map is small enough you won't even be able to read a single register in a read which is going to be annoying. Having either a lower bound or a more generous upper bound would be better. Please also write normal conditional statements, the ternery operator isn't great for legibility. --GPJrCs/72TxItFYR Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAl5mMRUACgkQJNaLcl1U h9C4NAf+Mxcnob0fXXEudywtr6lfYoOXJrMvrki+FNisnkiyj2VuPFMVNirxZbgW U9buihcu/SZzhoPXOhuglsoUHmvnLWXFy7nOeJyCOzeNOaBxZ8ZcQdNFnrYUTK0r NTi/I91MZxmQDKz5aI2m+6a5xhordF4wEUnZ6SwU8Dy2DOtA+rzz17eMNUhkY9oK 5TcgB6VA3VpjgjX/V2YjvEIhGfwKpJMd7s/WQNbdVZ8gOCTNg1TSqP6cZ6wo5Sup 8fDsOHE/3VcKsTCxckHEVx+TWh8ENhzUXha90KB/+Yk3DzB9prUilm/cDKdRAwPu hPAhJrHyCWNhiktCryUbOC2y83kY/A== =2rp2 -----END PGP SIGNATURE----- --GPJrCs/72TxItFYR--