From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753005AbbBSLEp (ORCPT ); Thu, 19 Feb 2015 06:04:45 -0500 Received: from mail-wg0-f49.google.com ([74.125.82.49]:47352 "EHLO mail-wg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752379AbbBSLEo (ORCPT ); Thu, 19 Feb 2015 06:04:44 -0500 Message-ID: <54E5C347.9070105@linaro.org> Date: Thu, 19 Feb 2015 11:04:39 +0000 From: Srinivas Kandagatla User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Mark Brown CC: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 1/2] regmap: Add range check in _regmap_raw_read() References: <1424335193-7431-1-git-send-email-srinivas.kandagatla@linaro.org> <1424335239-7475-1-git-send-email-srinivas.kandagatla@linaro.org> <20150219102750.GC3198@finisterre.sirena.org.uk> In-Reply-To: <20150219102750.GC3198@finisterre.sirena.org.uk> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/02/15 10:27, Mark Brown wrote: > On Thu, Feb 19, 2015 at 08:40:39AM +0000, Srinivas Kandagatla wrote: > >> + /* Check for readable registers before we start */ >> + for (i = 0; i < count; i++) >> + if (!regmap_readable(map, reg + (i * map->reg_stride))) >> + return -EINVAL; > > That's starting to look pretty expensive especially if what we're > looking for is just max_register really... This is one of the reasons Yes, I totally agree, this call would be expensive. Initially I had some thing like this, and it works for me. + if (map->max_register && + (reg > map->max_register || + ((reg + (count - 1) * map->reg_stride) > map->max_register))) + return -EINVAL; > we're not religious about checking for readability everywhere, and > obviously even if we avoid triggering this particular thing we still > have to cope with both the caller and devices that didn't specify > readability. A cheaper check for just max_register would be less > concerning but it feels like we're trying to paper over a symptom with > this rather than fix a problem. Yes, just checking max_register would solve the issue for me, I think I over done the patch.. I will resend with just max_register check. >