Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp828970pxx; Thu, 29 Oct 2020 15:49:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwn3zPt0lloEASotpwEEiEjHWakAzLn6Bhnz+CaEpqElt1pgW/rMW3owbNjKBvoLC8A9FsH X-Received: by 2002:a17:906:3b43:: with SMTP id h3mr6241870ejf.542.1604011755694; Thu, 29 Oct 2020 15:49:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604011755; cv=none; d=google.com; s=arc-20160816; b=P3If+GG/AmFsuuJXDnOJjO6n15NdaURIGEWy0S/puUujoquhepYcW7gmY+vUWGIn/D FECe6uiAdftYOnNyddNenXVJ0AKhu1iJFeibP4W+sgcRhfoh21XRDDTszgSMAWr4tgY0 gD74CIol3WDu9A/hO2HU/RUww0uoHs017r8/wXQJxo5XyNYKShl9ISY75CW5dB1WKE6t i838sgF75uoRVmtpTn0rUJW8Lgf9oY8/vOMemONtc0j2sPoFgZjMQh841Lc8twr6ZRQn QPPdNy8s7daWGPMsMBlVgL4au6FihpZjZpL0IQ6ArEtEhD3o+rl44JMS3AC0Tx+7j4fy b/dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DSemsUvp150q/YoQcpUh5xIjPo8EWtcJAt/Hux4oQF0=; b=XxnZ34LlgnGnBOValijO6YDoxBHJR7vxgKGxYVkfz8R9qv6Sr/kG/V7pakSwiR/qud Db0qZ4S89u6r14O08MecRbxEeF+8eJHuridZF8I31LrcoRxOICmE6y8j53ApL/sWfk1m 0a6UXtgK4z3DpPjE9fBnGqlowB2nCgRiSBdLduNBNf2MtHUMPYLokb3x/jNKiD3MqvqX jros1EFMg++lnpB52FqcvRU65xUAYhyJubLI54MgzXw2FtSNsM9fEpa/xd+SAYTVBvkL /ab02hOt+ndfmQveysazCzvwqSI+ipW+izrXnQhcDC3Dp+GHayFXDfWU7Do0ek8Jf/Y1 oj9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Uf1mOXg9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o7si2778847ejr.747.2020.10.29.15.48.52; Thu, 29 Oct 2020 15:49:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Uf1mOXg9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725856AbgJ2WpG (ORCPT + 99 others); Thu, 29 Oct 2020 18:45:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:50236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725769AbgJ2WpF (ORCPT ); Thu, 29 Oct 2020 18:45:05 -0400 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A67872151B; Thu, 29 Oct 2020 22:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604011504; bh=1v9CTsEcGCgtoQ3mFiM/G5rvasL5DfAEHGbNZndBwFE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Uf1mOXg9wfRgP+VnI3PH9Fb79G11G/jl7u/fmg6ASSDcR9HVAccCHwLoT32tm/hgV uGo4btKOD6SmKgoHOJpMC2BULYG3rxeiVlFtM1A5KeoQ6LjV3xZBP8/Bx0Xt3ieV9M 9ePSuEUSyGLPPciQqQP1xcCHIIE82Vzx3dAwTpcU= Received: by mail-qv1-f54.google.com with SMTP id w9so2060700qvj.0; Thu, 29 Oct 2020 15:45:04 -0700 (PDT) X-Gm-Message-State: AOAM5332mT/QD4F8UKScYQHMWm+o4zQPxAdUC/xLjWif7MlwqS0rr7B8 ZK02gtOUlTV4WsAvIjw9AdAEH2pbzVrmRk3DbA8= X-Received: by 2002:a0c:b58c:: with SMTP id g12mr6923502qve.16.1604011503669; Thu, 29 Oct 2020 15:45:03 -0700 (PDT) MIME-Version: 1.0 References: <15a044d3ba23f00c31fd09437bdd3e5924bb91cd.1603055402.git.syednwaris@gmail.com> In-Reply-To: <15a044d3ba23f00c31fd09437bdd3e5924bb91cd.1603055402.git.syednwaris@gmail.com> From: Arnd Bergmann Date: Thu, 29 Oct 2020 23:44:47 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v12 4/4] gpio: xilinx: Utilize generic bitmap_get_value and _set_value To: Syed Nayyar Waris Cc: Linus Walleij , Andrew Morton , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , William Breathitt Gray , Michal Simek , Bartosz Golaszewski , Andy Shevchenko , Linux ARM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 18, 2020 at 11:44 PM Syed Nayyar Waris wrote: > > This patch reimplements the xgpio_set_multiple() function in > drivers/gpio/gpio-xilinx.c to use the new generic functions: > bitmap_get_value() and bitmap_set_value(). The code is now simpler > to read and understand. Moreover, instead of looping for each bit > in xgpio_set_multiple() function, now we can check each channel at > a time and save cycles. This now causes -Wtype-limits warnings in linux-next with gcc-10: > + u32 *const state = chip->gpio_state; > + unsigned int *const width = chip->gpio_width; > + > + DECLARE_BITMAP(old, 64); > + DECLARE_BITMAP(new, 64); > + DECLARE_BITMAP(changed, 64); > + > + spin_lock_irqsave(&chip->gpio_lock[0], flags); > + spin_lock(&chip->gpio_lock[1]); > + > + bitmap_set_value(old, state[0], 0, width[0]); > + bitmap_set_value(old, state[1], width[0], width[1]); In file included from ../include/linux/cpumask.h:12, from ../arch/x86/include/asm/cpumask.h:5, from ../arch/x86/include/asm/msr.h:11, from ../arch/x86/include/asm/processor.h:22, from ../arch/x86/include/asm/timex.h:5, from ../include/linux/timex.h:65, from ../include/linux/time32.h:13, from ../include/linux/time.h:73, from ../include/linux/stat.h:19, from ../include/linux/module.h:13, from ../drivers/gpio/gpio-xilinx.c:11: ../include/linux/bitmap.h:639:18: warning: array subscript [1, 67108864] is outside array bounds of 'long unsigned int[1]' [-Warray-bounds] 639 | map[index + 1] |= value >> space; | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ In file included from ../include/linux/kasan-checks.h:5, from ../include/asm-generic/rwonce.h:26, from ./arch/x86/include/generated/asm/rwonce.h:1, from ../include/linux/compiler.h:246, from ../include/linux/build_bug.h:5, from ../include/linux/bits.h:22, from ../include/linux/bitops.h:6, from ../drivers/gpio/gpio-xilinx.c:8: ../drivers/gpio/gpio-xilinx.c:144:17: note: while referencing 'old' 144 | DECLARE_BITMAP(old, 64); | ^~~ ../include/linux/types.h:11:16: note: in definition of macro 'DECLARE_BITMAP' 11 | unsigned long name[BITS_TO_LONGS(bits)] | ^~~~ In file included from ../include/linux/cpumask.h:12, from ../arch/x86/include/asm/cpumask.h:5, from ../arch/x86/include/asm/msr.h:11, from ../arch/x86/include/asm/processor.h:22, from ../arch/x86/include/asm/timex.h:5, from ../include/linux/timex.h:65, from ../include/linux/time32.h:13, from ../include/linux/time.h:73, from ../include/linux/stat.h:19, from ../include/linux/module.h:13, from ../drivers/gpio/gpio-xilinx.c:11: The compiler clearly tries to do range-checking here and notices that the index into the fixed-length array on the stack is not correctly bounded. It seems this would happen whenever width[0] + width[1] is larger than 64. I have just submitted patches for all other -Wtype-limits warnings and would like to enable this option by default. Can you try to find a way to make this code safer? I would expect that you need a variant of bitmap_set_value() that takes an explicit ceiling here, and checks the stand and nbits values against that. Arnd