From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8852CC4742C for ; Tue, 10 Nov 2020 22:00:58 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CAFD420781 for ; Tue, 10 Nov 2020 22:00:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1OaWwq8O"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qeXZe4BA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CAFD420781 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XI37IOYCk0oSyU5+JyL0u6WD3Lxeo17wwoPobDK0glQ=; b=1OaWwq8O1G0zJWaPxNV0RAy/o IZJZyq3o38Bv4ouu9EX99xN+7n/80MfXGQMnjaAHWtC6vfHd2nyS9WIlsAjAUKaDeoPyBBZvrlLUm h3B0wxWhRzm5EK29FLTBlo/vdKOd99JtKQLOBn7MhWlhGymNq+wB9M8Vnniod/PxL6/lX9SdhpfRg KPdggeuYbVx08hH87gXhghKFqfd4Iz+z8KS9PNzpoC43DpEP7DpWSbAz82FkNRhSU7IaYkTvHW5Xg qgzL3PjDuaM1auK4LQvJou8ETuCVEFjshET66SE4xWyPOKGoFspG1U4cxG3LOe0ARBEc15e9AS9Z2 jAf9Bn4kA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbgf-0003Ak-IX; Tue, 10 Nov 2020 22:00:25 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbgc-00039w-PB for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:00:23 +0000 Received: by mail-pg1-x542.google.com with SMTP id f18so6964081pgi.8 for ; Tue, 10 Nov 2020 14:00:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZkeNKItXvG55Kf84CvoIRBs6Edwo+I3OqlGP+dGuXqE=; b=qeXZe4BA9SCO4hDnfzJwhsIzRf2xqQGyKDWlcBpxlE1NdOLxQSaZqpKkCNvM4WNMbb q8mVqYA49vkoPIXmtClIbZ5pvNY+uaE2KmgG7wIXLfJHc4Q1oC2t59wYKxLak79GSYe6 swqejvNBa/nf2LCcfidaEsfX0eBJ9OdvyFv438HXth5WhrO/QH9Q2rdsc+pvlD18V8IM LA1whs8OttevAb6pZF75y4D8FTfqTXAMznR4aKWcF41UCz6OHUkIwe1FGXrUNmRlrrXI 6FfnKKudv+hMtCamAHhxZmZRn/A2NAOGojYnR2uQOT8vbr6jZlPx8hU0FTh6kILDj4jl oDRQ== 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=ZkeNKItXvG55Kf84CvoIRBs6Edwo+I3OqlGP+dGuXqE=; b=Z1aPADW154jgifJntWFngpzVhTAk5VxGpeZPGrdQx5VNZKmIopTBhSgxCIT5fPnz9X tHZA2jRQSaagnLe1J7DbaEtoIOnoHL1pfzJYOSwOeWHx3TQd6S61/9y4XALVByp4mU/d 9ldBBLRtLtEcWxfEK1/BAiSemWkaGaGdLXfjadb41GMtQD7uStPbnnkgL5oJwV+iJtQQ U0XJBfpSr52GgV7ip/YjinWmlHwMJKf8HFP+4BEmGFF8e801oo5tq8iq3eyWAi1q2OQj UuLLI1XARzHlAVkzmHNw8FgeeFGfk6zpXqAAPPQdPGeWFD5x3J6dHF+d0MK/KmK2t1mL 86HQ== X-Gm-Message-State: AOAM532xBJmAI6vNwJx5q1JItexmqYGGAW6lyeN+VFkgqjZIZ/LZiwXN eWzpIvsx6AqgWuMLVPa/TLtEw9dratk= X-Google-Smtp-Source: ABdhPJzo+VhB1ql5vArn/z1a28Riu0xD0JYc/jpIkO899WCTKEu0UtJ+gQb0z0Rgyh795jEXYojMfQ== X-Received: by 2002:a62:84d2:0:b029:18a:f574:fded with SMTP id k201-20020a6284d20000b029018af574fdedmr20647846pfd.31.1605045619959; Tue, 10 Nov 2020 14:00:19 -0800 (PST) Received: from syed ([223.225.0.141]) by smtp.gmail.com with ESMTPSA id w65sm113758pfw.145.2020.11.10.14.00.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2020 14:00:19 -0800 (PST) Date: Wed, 11 Nov 2020 03:30:04 +0530 From: Syed Nayyar Waris To: arnd@kernel.org, vilhelm.gray@gmail.com Subject: Re: [PATCH v12 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value Message-ID: <20201110220004.GA25801@syed> References: <20201109134128.GA5596@shinobu> <20201109164529.GA28710@syed.domain.name> <20201109171140.GA14045@shinobu> <20201109172220.GI4077@smile.fi.intel.com> <20201109173107.GA14643@shinobu> <20201110123538.GA3193@shinobu> <20201110174316.GA12192@shinobu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201110174316.GA12192@shinobu> User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_170022_861655_392705DC X-CRM114-Status: GOOD ( 36.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Bartosz Golaszewski , Linus Walleij , Michal Simek , "linux-kernel@vger.kernel.org" , "open list:GPIO SUBSYSTEM" , Andrew Morton , Andy Shevchenko , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Nov 10, 2020 at 12:43:16PM -0500, William Breathitt Gray wrote: > On Tue, Nov 10, 2020 at 10:52:42PM +0530, Syed Nayyar Waris wrote: > > On Tue, Nov 10, 2020 at 6:05 PM William Breathitt Gray > > wrote: > > > > > > On Tue, Nov 10, 2020 at 11:02:43AM +0100, Michal Simek wrote: > > > > > > > > > > > > On 09. 11. 20 18:31, William Breathitt Gray wrote: > > > > > On Mon, Nov 09, 2020 at 07:22:20PM +0200, Andy Shevchenko wrote: > > > > >> On Mon, Nov 09, 2020 at 12:11:40PM -0500, William Breathitt Gray wrote: > > > > >>> On Mon, Nov 09, 2020 at 10:15:29PM +0530, Syed Nayyar Waris wrote: > > > > >>>> On Mon, Nov 09, 2020 at 03:41:53PM +0100, Arnd Bergmann wrote: > > > > >> > > > > >> ... > > > > >> > > > > >>>> static inline void bitmap_set_value(unsigned long *map, > > > > >>>> - unsigned long value, > > > > >>>> + unsigned long value, const size_t length, > > > > >>>> unsigned long start, unsigned long nbits) > > > > >>>> { > > > > >>>> const size_t index = BIT_WORD(start); > > > > >>>> @@ -15,6 +15,10 @@ static inline void bitmap_set_value(unsigned long *map, > > > > >>>> } else { > > > > >>>> map[index + 0] &= ~BITMAP_FIRST_WORD_MASK(start); > > > > >>>> map[index + 0] |= value << offset; > > > > >>>> + > > > > >>>> + if (index + 1 >= length) > > > > >>>> + __builtin_unreachable(); > > > > >>>> + > > > > >>>> map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); > > > > >>>> map[index + 1] |= value >> space; > > > > >>>> } > > > > >>> > > > > >>> Hi Syed, > > > > >>> > > > > >>> Let's rename 'length' to 'nbits' as Arnd suggested, and rename 'nbits' > > > > >>> to value_width. > > > > >> > > > > >> length here is in longs. I guess this is the point of entire patch. > > > > > > > > > > Ah yes, this should become 'const unsigned long nbits' and represent the > > > > > length of the bitmap in bits and not longs. > > > > Hi William, Andy and All, > > > > Thank You for reviewing. I was looking into the review comments and I > > have a question on the above. > > > > Actually, in bitmap_set_value(), the intended comparison is to be made > > between 'index + 1' and 'length' (which is now renamed as 'nbits'). > > That is, the comparison would look-like as follows: > > if (index + 1 >= nbits) > > > > The 'index' is getting populated with BIT_WORD(start). > > The 'index' variable in above is the actual index of the bitmap array, > > while in previous mail it is suggested to use 'nbits' which represent > > the length of the bitmap in bits and not longs. > > > > Isn't it comparing two different things? index of array (not the > > bit-wise-length) on left hand side and nbits (bit-wise-length) on > > right hand side? > > > > Have I misunderstood something? If yes, request to clarify. > > > > Or do I have to first divide 'nbits' by BITS_PER_LONG and then compare > > it with 'index + 1'? Something like this? > > > > Regards > > Syed Nayyar Waris > > The array elements of the bitmap memory region are abstracted away for > the covenience of the users of the bitmap_* functions; the driver > authors are able to treat their bitmaps as just a set of contiguous bits > and not worry about where the division between array elements happen. > > So to match the interface of the other bitmap_* functions, you should > take in nbits and figure out the actual array length by dividing by > BITS_PER_LONG inside bitmap_set_value(). Then you can use your > conditional check (index + 1 >= length) like you have been doing so far. > > William Breathitt Gray Hi Arnd, Sharing a new version of bitmap_set_value(). Let me know if it looks good and whether it suppresses the compiler warning. The below patch is created against the v12 version of bitmap_set_value(). -static inline void bitmap_set_value(unsigned long *map, - unsigned long value, - unsigned long start, unsigned long nbits) +static inline void bitmap_set_value(unsigned long *map, unsigned long nbits, + unsigned long value, unsigned long value_width, + unsigned long start) { - const size_t index = BIT_WORD(start); + const unsigned long index = BIT_WORD(start); + const unsigned long length = BIT_WORD(nbits); const unsigned long offset = start % BITS_PER_LONG; const unsigned long ceiling = round_up(start + 1, BITS_PER_LONG); const unsigned long space = ceiling - start; - value &= GENMASK(nbits - 1, 0); + value &= GENMASK(value_width - 1, 0); - if (space >= nbits) { - map[index] &= ~(GENMASK(nbits - 1, 0) << offset); + if (space >= value_width) { + map[index] &= ~(GENMASK(value_width - 1, 0) << offset); map[index] |= value << offset; } else { map[index + 0] &= ~BITMAP_FIRST_WORD_MASK(start); map[index + 0] |= value << offset; - map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); + + if (index + 1 >= length) + __builtin_unreachable(); + + map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + value_width); map[index + 1] |= value >> space; } } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel