Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp433347rdb; Thu, 2 Nov 2023 07:52:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1tXT5JwjCqba4lc/J3xVJS7TQRbivuPRYzeB9bwLGJcx6jggNEkMCgrcjmArZTk0A/rFx X-Received: by 2002:a17:90a:740b:b0:27d:20f5:3629 with SMTP id a11-20020a17090a740b00b0027d20f53629mr18370697pjg.46.1698936774966; Thu, 02 Nov 2023 07:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698936774; cv=none; d=google.com; s=arc-20160816; b=BoPKzFIFEt4yiHexIR283cWTpET+5FryOrgQGCRax/ovRxqg1Z2G/qLrcBWBuSIzH5 BhkuS6UIbexjjPbkhrgvX4i0FZgT6u+tXSfeHX9OEDXGVE35/G6TynpVvY4oE6ZFWkwb 4dP1uXvPKr2FDvq5CZFKIelxygDu/MoXBuJIKZpVCpTswHQNnEigAaRaMhC/Hg9Nu+ND GL7z5W+S4wjZ92CUltZixvOsJOGs+OZhdsq5mGeqSZwPLMKKTr4eXaFanaLZOvgjaWBR cxoKaxZ8ZPKdowO0+0Rxj36p3AcZxvCiPpmvDmne4tsIEoxReSeH9toXAxa/hJW+gL/+ Tlyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xbLEZ3Dvy6vK8c71cfbvowkvFzjH6f30mEWwF7xpWnk=; fh=v0dwQZDeXzi4p34iPb4IHCCbo4RuXlCMOBkY0w7IcxE=; b=skuqnoCm40gVO32yLvY8R1PHBtw/ckDzU5GzyTtVrlzIEXbghmEi6J7hHyKiY5/odo lE1HmDr2Vxs3YGB/iG2r33BXa2pwQXGXdogbl7GQgSdf7m4lGbp+sDKlTf0LG8z5aloF 3VwX58x27zPeh+X1LLZSlNFBsGoRbNM4LoFN8uJzrkD9e+3eS1TKbvmcP3Ax7gI/zGNN PScWRgWxX6lkmQ47tUnAFTr2noJQKnjtRlitmnIkipeDugGh1qzYi5DA/MSsBpYTVqU2 VMAE9DZR2nEep82wKAx0a472ybF4V4MaDfqLzSGje+lrdb5jqBLJ7Xkp6W+TWtN3Byp5 Sgnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IAPghaxP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id nv13-20020a17090b1b4d00b00277816efefasi1216pjb.106.2023.11.02.07.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 07:52:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IAPghaxP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 19533807C74F; Thu, 2 Nov 2023 07:52:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229596AbjKBOwg (ORCPT + 99 others); Thu, 2 Nov 2023 10:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbjKBOwf (ORCPT ); Thu, 2 Nov 2023 10:52:35 -0400 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DF0A11B for ; Thu, 2 Nov 2023 07:52:29 -0700 (PDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5a7af52ee31so12278847b3.2 for ; Thu, 02 Nov 2023 07:52:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698936749; x=1699541549; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xbLEZ3Dvy6vK8c71cfbvowkvFzjH6f30mEWwF7xpWnk=; b=IAPghaxPakTkeRKc0a8hHSHGrdyQTBCC1HXsGMy1RpMmyKowY1RdWXhSoW1Q2gHP6b Li/4kVvbg93bsUkSvp5EbSYKb9JdLUUd6pnRWY8EVdSRsS2JztFt8rF2M5SvJxHJRHPY +BLuuxgMq7zdikCJGs9lL1utzZg0slPx/IZn8UvxxJD29RXztci9P8TrEaUrU66/hMMb 0h3q2mqhZ44RfZlLht292+1q2yR6PAvxvXKar5EJu65elARv3xWals5w1oktg8ZVspiD kFPiPQs832ri9ROO/2Vk7CtrIvV7eSeXROwCggzGWxDbOvCmbW8rvZrdMyZjRIUIEmXT xW3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698936749; x=1699541549; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xbLEZ3Dvy6vK8c71cfbvowkvFzjH6f30mEWwF7xpWnk=; b=WxdrK7bt9DuFeSIWcoLbZ9b4RSWjKBqyhf8m5quOkFd5OSEQ+x+qlF+tWQQKLx065i 655tulw/eDSC8VKhBYpv7mYDsEvZ/Ugmc54fIgyPgrRpvnUxa0BeOuTzBdo7MqY3Bo13 2XFxNTVmrojr3VskRgGV1tSLMXNNruB3wm5r9A/etuIO0BQD6Bihp+gMM2tJ28IyDYfi TCLGBY5AODoqiTdM2GgwNnIqJOCWjyvN3EaV/BMrsBTTxE7Ynz2P3sTmiN4Xuzm7sCsS ofX1GpKy0fryek6aI/DroLTmlNf0BBvlEsEg3QpM4bqF+qEhQFfjHyhSQUMpG9BriSMc 0V4w== X-Gm-Message-State: AOJu0YwZix9ncBawPLN2RcNKu7YCgkTScQDa4WiJ8RRpREhefka/G04y LkmLTW89YdMIkMyXZLKeH6BMjzvaYqk/Kf1oP9LLAA== X-Received: by 2002:a05:690c:ecd:b0:5b3:f5f8:c5bf with SMTP id cs13-20020a05690c0ecd00b005b3f5f8c5bfmr6756787ywb.9.1698936748715; Thu, 02 Nov 2023 07:52:28 -0700 (PDT) MIME-Version: 1.0 References: <20231101025802.3744-1-tychang@realtek.com> <20231101025802.3744-2-tychang@realtek.com> <12ada22542cf4b2991da2e8c2858c5d7@realtek.com> In-Reply-To: <12ada22542cf4b2991da2e8c2858c5d7@realtek.com> From: Linus Walleij Date: Thu, 2 Nov 2023 15:52:16 +0100 Message-ID: Subject: Re: [PATCH 1/2] gpio: realtek: Add GPIO support for RTD SoC variants To: =?UTF-8?B?VFlfQ2hhbmdb5by15a2Q6YC4XQ==?= Cc: Bartosz Golaszewski , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "linux-gpio@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Kees Cook Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 02 Nov 2023 07:52:50 -0700 (PDT) On Thu, Nov 2, 2023 at 1:40=E2=80=AFPM TY_Chang[=E5=BC=B5=E5=AD=90=E9=80=B8= ] wrote: > >On Wed, Nov 1, 2023 at 3:58=E2=80=AFAM Tzuyi Chang = wrote: > >> +static unsigned int rtd_gpio_deb_offset(struct rtd_gpio *data, > >> +unsigned int offset) { > >> + return data->info->deb_offset[offset / 8]; } > > > >So this is clearly counted by the GPIO number offset and the GPIO number > >determines how far into the array we can index. > > > >It looks a bit dangerous, it it possible to encode the array lengths bet= ter? > > I think I can add array size members for each offset array within the > rtd_gpio_info structure and utilize them to prevent accessing elements ou= tside the array. I don't know about that for constant arrays, if you look at recent commits from Kees Cook you will find examples of how to use the compiler helpers for dynamic arrays, e.g. git log -p --author=3DKees will find you things like this: @@ -60,7 +60,7 @@ struct reset_control { struct reset_control_array { struct reset_control base; unsigned int num_rstcs; - struct reset_control *rstc[]; + struct reset_control *rstc[] __counted_by(num_rstcs); }; So the compiler instruction __counted_by() is used pointing back to the variable above to avoid outofbounds accesses. BUT: those are *dynamic* arrays, placed *last* in the struct. You have several *constant* arrays, in the same struct (and C allows this). I don't really know what is the best practice for constants, maybe Kees has some pointers? Maybe what you have is the best we can do. Yours, Linus Walleij