Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3643422pxb; Mon, 4 Oct 2021 06:45:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx55plG7PP+Zn6os/Z/TD3T0lnLCBQ4TB3JL9teFmTbUTgHUo/iUXqG39IiEr+3DigEfa9n X-Received: by 2002:a17:906:e4b:: with SMTP id q11mr17191326eji.234.1633355111471; Mon, 04 Oct 2021 06:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633355111; cv=none; d=google.com; s=arc-20160816; b=QoUr/dej+CXbYSKHdQk/R7OZUXqmCSAqIV9Z1F2M1W6assJlSyrtEqZtsTvVR86IOD eXxEc2ChEWYJZzDBXBzfZz/ZcaB/GGpS9DJVpvtJPo7eKFDi+k5JaI+rFs4lh0l5aw0t JppibzOcPwb4G1C9IFMhBQDWyhnpjc03GZ31oYbrQT3HDLI0o5jC7VLGU5GEB0Ve+YDu YAbv7SZtln2nyGSzT1vNf7gtlmw3Q2U4B2OG8CVWmOrQfi50ps0QLN8g1x+htudkFemF 4FSvQdaUKTrcJu+GKCK6/+ugsb9uYJttKZ5YIo7CcMNqRDGNIdA4phUUm0Lx2M0Qa1Ab fgXw== 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; bh=dv9RspM3ctxvAuhOcHTg3KizZsDDkdv4PFnf5HpmAKA=; b=IcZUT2d+uZVymL2zJXjt+9oxUj6kBwvTBe26q0V1lMLn0Oha3qPOf9OsNe0sNeepaR C5DaMRvoxE6fewEgfiFL2zgXiXk14tG8xvkEEvSdcynPjieCzZjcIqrdSUH3PEoXXLv3 jnEoc80Wh/+3E8TOFZoF6YpmV+S/n1JcsCGXP1gxw7XVaVio6n2j4SuJeXcaE/0M6ktk 6bJIHwjqG1IRIXYVkqGii/uqoqjJrHS2pi+pOEInaBE0CXtIkPsIg4v+UOL5qTcS7BaU YGtJkBDqj0qWnHJhwuzm9ScEwa+bkx4pEKb30V/6mFhD0zJJmSlfWR+OhkBhGVazarcV McfA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q22si17530449edw.33.2021.10.04.06.44.38; Mon, 04 Oct 2021 06:45:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238759AbhJDNmX (ORCPT + 99 others); Mon, 4 Oct 2021 09:42:23 -0400 Received: from mail-vs1-f42.google.com ([209.85.217.42]:40459 "EHLO mail-vs1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238456AbhJDNka (ORCPT ); Mon, 4 Oct 2021 09:40:30 -0400 Received: by mail-vs1-f42.google.com with SMTP id l19so19546224vst.7; Mon, 04 Oct 2021 06:38:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dv9RspM3ctxvAuhOcHTg3KizZsDDkdv4PFnf5HpmAKA=; b=QCyv1O3TbhXncu/7Q4GUriwbetQXcJ4OzFXDnArEhkepP+clgaGb62ZbALLiuY9KrW Vv0MvmKzCX8BWviEHwmjmiOAqLPniuRFTiXwtIs0Mzmp7lDm42g2c7/ty4/VIN1ypTFH sVZI51bQkcyzGAUkEosxFu8+cSNdulHDmRVwxahCAIU/9pTcfO3QYg9Qa41uF6PU9zc9 1gpRjuL32JnwN4oMV55HLWu2ZE1hTyWFvPmxsIi/ctCh1PPxI/LKJNg0zv8hmCM3hbF3 O3ghBwUPdmsOP0pVFS0poBesslXLkMzN5stpxWFc/gHYkPiP6zPJ6f4wUigdkK5LAqxa 763A== X-Gm-Message-State: AOAM5302zuLNNVEl6caE1qwGtJq7INqODaoCdzhiYgQwQ2gc8qva9BEI YRfK5QlCHs0J6/GGRs6mzQjEbDMRgBemTBl5AG0= X-Received: by 2002:a67:cb0a:: with SMTP id b10mr12782999vsl.9.1633354721081; Mon, 04 Oct 2021 06:38:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Geert Uytterhoeven Date: Mon, 4 Oct 2021 15:38:29 +0200 Message-ID: Subject: Re: [PATCH] gpio: aggregator: Wrap access to gpiochip_fwd.tmp[] To: Andy Shevchenko Cc: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, On Mon, Oct 4, 2021 at 3:23 PM Andy Shevchenko wrote: > On Mon, Oct 4, 2021 at 3:47 PM Geert Uytterhoeven > wrote: > > The tmp[] member of the gpiochip_fwd structure is used to store both the > > temporary values bitmap and the desc pointers for operations on multiple > > GPIOs. As both are arrays with sizes unknown at compile-time, accessing > > them requires offset calculations, which are currently duplicated in > > gpio_fwd_get_multiple() and gpio_fwd_set_multiple(). > > > > Introduce (a) accessors for both arrays and (b) a macro to calculate the > > needed storage size. This confines the layout of the tmp[] member into > > a single spot, to ease maintenance. > > ... > > > +#define fwd_tmp_descs(fwd) (void *)&(fwd)->tmp[BITS_TO_LONGS((fwd)->chip.ngpio)] > > + > > +#define fwd_tmp_size(ngpios) (BITS_TO_LONGS((ngpios)) + (ngpios)) > > ... > > > - fwd = devm_kzalloc(dev, struct_size(fwd, tmp, > > - BITS_TO_LONGS(ngpios) + ngpios), GFP_KERNEL); > > + fwd = devm_kzalloc(dev, struct_size(fwd, tmp, fwd_tmp_size(ngpios)), > > + GFP_KERNEL); > > Shouldn't we rather use devm_bitmap_zalloc() / bitmap_free()? That's not sufficient: the bitmap is only one part. There are one fixed-size and two variable-size objects to allocate. Yes, they can be allocated separately, at the expense of more allocations, and more data (pointers) to allocate to keep track of all those objects. > > > if (!fwd) > > return ERR_PTR(-ENOMEM); Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds