[{"id":3669057,"web_url":"http://patchwork.ozlabs.org/comment/3669057/","msgid":"<acPUYlO4VUDNctBX@ashevche-desk.local>","list_archive_url":null,"date":"2026-03-25T12:26:10","subject":"Re: [PATCH] gpiolib: fix hogs with multiple lines","submitter":{"id":8583,"url":"http://patchwork.ozlabs.org/api/people/8583/","name":"Andy Shevchenko","email":"andriy.shevchenko@linux.intel.com"},"content":"On Wed, Mar 25, 2026 at 11:18:32AM +0100, Bartosz Golaszewski wrote:\n> After moving GPIO hog handling into GPIOLIB core, we accidentally stopped\n> supporting devicetree hog definitions with multiple lines like so:\n> \n> \thog {\n> \t\tgpio-hog;\n> \t\tgpios = <3 0>, <4 GPIO_ACTIVE_LOW>;\n> \t\toutput-high;\n> \t\tline-name = \"foo\";\n> \t};\n> \n> Restore this functionality to fix reported regressions.\n\n...\n\n> +\tret = fwnode_property_read_u32(gc_node, \"#gpio-cells\", &cells);\n> +\tif ((ret && is_of_node(fwnode)) || (!ret && (argc % cells)))\n>  \t\treturn -EINVAL;\n\nHmm... Shouldn't we return the proper error code in the first case?\n\n\tif (ret && is_of_node(fwnode))\n\t\treturn ret;\n\tif (!ret && (argc % cells))\n\t\treturn -EINVAL;\n\n...\n\n> +\tu32 *gpios __free(kfree) = kcalloc(argc, sizeof(u32), GFP_KERNEL);\n\nsizeof(*gpios)\n\n> +\tif (!gpios)\n> +\t\treturn -ENOMEM;","headers":{"Return-Path":"\n <linux-gpio+bounces-34132-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-gpio@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256\n header.s=Intel header.b=mhfrYlmT;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c09:e001:a7::12fc:5321; helo=sto.lore.kernel.org;\n envelope-from=linux-gpio+bounces-34132-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com\n header.b=\"mhfrYlmT\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=198.175.65.21","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=linux.intel.com"],"Received":["from sto.lore.kernel.org (sto.lore.kernel.org\n [IPv6:2600:3c09:e001:a7::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fgmPH3C6bz1xy3\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 23:26:59 +1100 (AEDT)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sto.lore.kernel.org (Postfix) with ESMTP id 6EABC303C91B\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 12:26:17 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 2B9713D16F5;\n\tWed, 25 Mar 2026 12:26:16 +0000 (UTC)","from mgamail.intel.com (mgamail.intel.com [198.175.65.21])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id D698B3A2570;\n\tWed, 25 Mar 2026 12:26:14 +0000 (UTC)","from fmviesa010.fm.intel.com ([10.60.135.150])\n  by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 25 Mar 2026 05:26:15 -0700","from dalessan-mobl3.ger.corp.intel.com (HELO localhost)\n ([10.245.245.32])\n  by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 25 Mar 2026 05:26:12 -0700"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1774441576; cv=none;\n b=H2owf7XtQKEm1Mmb1DFqjgdlCBTkc7zNo11AjlWKV3h4Y3j4i173St/y1J5nkcEzRb3uOXZFz69Ku7LmhwIemtzeyxmDVzPFgb+59Nxd7LPlQHkdKu7ZkqDeqJPX4HsxuxwPBn9QIUo8uW0JSTx0g2n8s921epIvxCMHWt1cx+w=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1774441576; c=relaxed/simple;\n\tbh=RpEWiiE12rucC0CNHShHHd3yv+pJPdJM0e102etHC9w=;\n\th=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:\n\t Content-Type:Content-Disposition:In-Reply-To;\n b=NTaD0q7/J87fqXfSCZuHjxvFRlLOfcdpaFT8+seY17UWj4K3+YkxsrZO+pxOkN7v7PinxLGysCOD14NTX04A77fi7hOqEdAOpWx/oPBqAnT7NxPXoGckdCEh2524md4KGjPgslUQiAbjTYamQUmpeDmpePTlaxVqPRuv+7Ww0nc=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com;\n spf=pass smtp.mailfrom=linux.intel.com;\n dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com\n header.b=mhfrYlmT; arc=none smtp.client-ip=198.175.65.21","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n  t=1774441575; x=1805977575;\n  h=date:from:to:cc:subject:message-id:references:\n   mime-version:in-reply-to;\n  bh=RpEWiiE12rucC0CNHShHHd3yv+pJPdJM0e102etHC9w=;\n  b=mhfrYlmTuzh7hh/uhfFhw8JElb2T+Is+MennEnhF+tTHTdDZ6wKifRLH\n   TsK5AfwXTpj4wbdQSATvmJgAffoItPFQ+9eQrte+eh/jtKIQmqt/lv3C4\n   YcSMTwWcRZ4Mgp76nzXTYwDsa2Wj7yXToJ+LvgWkzNbsecTDEayt6Cs4t\n   zT9AFv9Dy11YW7TcOi+F1sZGW97KLzSq+jPB0p2psmI7bJrTORogfEo9+\n   X2EDIrLUkZlVHDnNsByCUIGxGxnWxeuWkBVMvom0StsKx2AE2svdBzWkP\n   mtTFb0JJta3NgXD17JPWfGC02NY8oQ6sld7MUMI2fRQdjKASGUYQVSevh\n   Q==;","X-CSE-ConnectionGUID":["XNaedTiHQgmfTL3VMWW5ag==","cgsopyOgRbqAbD/nhOz9iw=="],"X-CSE-MsgGUID":["CMoqL/aKQ9SQ3by/dGltXQ==","ms7fFVb3TyKgtZJtTxtkpQ=="],"X-IronPort-AV":["E=McAfee;i=\"6800,10657,11739\"; a=\"75357540\"","E=Sophos;i=\"6.23,140,1770624000\";\n   d=\"scan'208\";a=\"75357540\"","E=Sophos;i=\"6.23,140,1770624000\";\n   d=\"scan'208\";a=\"220261673\""],"X-ExtLoop1":"1","Date":"Wed, 25 Mar 2026 14:26:10 +0200","From":"Andy Shevchenko <andriy.shevchenko@linux.intel.com>","To":"Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>","Cc":"Linus Walleij <linusw@kernel.org>,\n\tBartosz Golaszewski <brgl@kernel.org>,\n\tMika Westerberg <mika.westerberg@linux.intel.com>,\n\tlinux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,\n\tGeert Uytterhoeven <geert@linux-m68k.org>","Subject":"Re: [PATCH] gpiolib: fix hogs with multiple lines","Message-ID":"<acPUYlO4VUDNctBX@ashevche-desk.local>","References":"<20260325-gpio-hogs-multiple-v1-1-7e3a7347f0d6@oss.qualcomm.com>","Precedence":"bulk","X-Mailing-List":"linux-gpio@vger.kernel.org","List-Id":"<linux-gpio.vger.kernel.org>","List-Subscribe":"<mailto:linux-gpio+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-gpio+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20260325-gpio-hogs-multiple-v1-1-7e3a7347f0d6@oss.qualcomm.com>","Organization":"Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6\n krs, Bertel Jungin Aukio 5, 02600 Espoo"}},{"id":3669276,"web_url":"http://patchwork.ozlabs.org/comment/3669276/","msgid":"<CAMuHMdVpQ_HmqXqB=MwJJYbNKgNvrb0ZdbNbiiz=CXK1qECBEQ@mail.gmail.com>","list_archive_url":null,"date":"2026-03-25T18:41:57","subject":"Re: [PATCH] gpiolib: fix hogs with multiple lines","submitter":{"id":703,"url":"http://patchwork.ozlabs.org/api/people/703/","name":"Geert Uytterhoeven","email":"geert@linux-m68k.org"},"content":"Hi Bartosz,\n\nOn Wed, 25 Mar 2026 at 11:18, Bartosz Golaszewski\n<bartosz.golaszewski@oss.qualcomm.com> wrote:\n> After moving GPIO hog handling into GPIOLIB core, we accidentally stopped\n> supporting devicetree hog definitions with multiple lines like so:\n>\n>         hog {\n>                 gpio-hog;\n>                 gpios = <3 0>, <4 GPIO_ACTIVE_LOW>;\n>                 output-high;\n>                 line-name = \"foo\";\n>         };\n>\n> Restore this functionality to fix reported regressions.\n>\n> Fixes: d1d564ec4992 (\"gpio: move hogs into GPIO core\")\n> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>\n> Closes: https://lore.kernel.org/all/CAMuHMdX6RuZXAozrF5m625ZepJTVVr4pcyKczSk12MedWvoejw@mail.gmail.com/\n> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>\n\nThanks, that fixes the issue I saw on Marzen\nTested-by: Geert Uytterhoeven <geert+renesas@glider.be>\n\n> --- a/drivers/gpio/gpiolib.c\n> +++ b/drivers/gpio/gpiolib.c\n> @@ -938,12 +938,12 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)\n>         struct fwnode_handle *gc_node = dev_fwnode(&gc->gpiodev->dev);\n>         struct fwnode_reference_args gpiospec;\n>         enum gpiod_flags dflags;\n> +       const char *name = NULL;\n>         struct gpio_desc *desc;\n>         unsigned long lflags;\n> -       const char *name;\n> +       size_t num_hogs;\n>         int ret, argc;\n> -       u32 gpios[3]; /* We support up to three-cell bindings. */\n> -       u32 cells;\n> +       u32 cells = 0;\n\nShouldn't the default be 2?\n\n>\n>         lflags = GPIO_LOOKUP_FLAGS_DEFAULT;\n>         dflags = GPIOD_ASIS;\n> @@ -952,43 +952,21 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)\n>         argc = fwnode_property_count_u32(fwnode, \"gpios\");\n>         if (argc < 0)\n>                 return argc;\n> -       if (argc > 3)\n> +\n> +       ret = fwnode_property_read_u32(gc_node, \"#gpio-cells\", &cells);\n\nShould this call be protected by is_of_node(), like in the old code?\n\n> +       if ((ret && is_of_node(fwnode)) || (!ret && (argc % cells)))\n>                 return -EINVAL;\n>\n> +       num_hogs = ret ? 1 : (argc / cells);\n\nWhile you avoid modulo and division by zero due to the check for ret,\nusing a default would let you always validate argc against cells,\nand remove the need for special casing num_hogs.\n\n> +\n> +       u32 *gpios __free(kfree) = kcalloc(argc, sizeof(u32), GFP_KERNEL);\n\nkzalloc_objs()?\n\n> +       if (!gpios)\n> +               return -ENOMEM;\n> +\n>         ret = fwnode_property_read_u32_array(fwnode, \"gpios\", gpios, argc);\n>         if (ret < 0)\n>                 return ret;\n>\n> -       if (is_of_node(fwnode)) {\n> -               /*\n> -                * OF-nodes need some additional special handling for\n> -                * translating of devicetree flags.\n> -                */\n> -               ret = fwnode_property_read_u32(gc_node, \"#gpio-cells\", &cells);\n> -               if (ret)\n> -                       return ret;\n> -               if (!ret && argc != cells)\n> -                       return -EINVAL;\n> -\n> -               memset(&gpiospec, 0, sizeof(gpiospec));\n> -               gpiospec.fwnode = fwnode;\n> -               gpiospec.nargs = argc;\n> -\n> -               for (int i = 0; i < argc; i++)\n> -                       gpiospec.args[i] = gpios[i];\n> -\n> -               ret = of_gpiochip_get_lflags(gc, &gpiospec, &lflags);\n> -               if (ret)\n> -                       return ret;\n> -       } else {\n> -               /*\n> -                * GPIO_ACTIVE_LOW is currently the only lookup flag\n> -                * supported for non-OF firmware nodes.\n> -                */\n> -               if (gpios[1])\n> -                       lflags |= GPIO_ACTIVE_LOW;\n> -       }\n> -\n>         if (fwnode_property_present(fwnode, \"input\"))\n>                 dflags |= GPIOD_IN;\n>         else if (fwnode_property_present(fwnode, \"output-low\"))\n> @@ -1000,11 +978,41 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)\n>\n>         fwnode_property_read_string(fwnode, \"line-name\", &name);\n>\n> -       desc = gpiochip_get_desc(gc, gpios[0]);\n> -       if (IS_ERR(desc))\n> -               return PTR_ERR(desc);\n> +       for (unsigned int i = 0; i < num_hogs; i++) {\n> +               if (is_of_node(fwnode)) {\n> +                       /*\n> +                        * OF-nodes need some additional special handling for\n> +                        * translating of devicetree flags.\n> +                        */\n> +                       memset(&gpiospec, 0, sizeof(gpiospec));\n> +                       gpiospec.fwnode = fwnode;\n> +                       gpiospec.nargs = cells;\n> +\n> +                       for (int j = 0; j < cells; j++)\n> +                               gpiospec.args[j] = gpios[i * cells + j];\n> +\n> +                       ret = of_gpiochip_get_lflags(gc, &gpiospec, &lflags);\n> +                       if (ret)\n> +                               return ret;\n> +               } else {\n> +                       /*\n> +                        * GPIO_ACTIVE_LOW is currently the only lookup flag\n> +                        * supported for non-OF firmware nodes.\n> +                        */\n> +                       if (gpios[i * cells + 1])\n\nThis depends on cells being non-zero, and thus having a proper default,\ntoo.\n\n> +                               lflags |= GPIO_ACTIVE_LOW;\n> +               }\n>\n> -       return gpiod_hog(desc, name, lflags, dflags);\n> +               desc = gpiochip_get_desc(gc, gpios[i * cells]);\n> +               if (IS_ERR(desc))\n> +                       return PTR_ERR(desc);\n> +\n> +               ret = gpiod_hog(desc, name, lflags, dflags);\n> +               if (ret)\n> +                       return ret;\n> +       }\n> +\n> +       return 0;\n>  }\n>\n>  static int gpiochip_hog_lines(struct gpio_chip *gc)\n\nGr{oetje,eeting}s,\n\n                        Geert","headers":{"Return-Path":"\n <linux-gpio+bounces-34169-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-gpio@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-gpio+bounces-34169-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.217.41","smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=linux-m68k.org","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fgwr52Yl9z1xy3\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 26 Mar 2026 05:47:17 +1100 (AEDT)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 4EB5430B5004\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 25 Mar 2026 18:42:14 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 6F42D33B6C6;\n\tWed, 25 Mar 2026 18:42:13 +0000 (UTC)","from mail-vs1-f41.google.com (mail-vs1-f41.google.com\n [209.85.217.41])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id C51A63242BA\n\tfor <linux-gpio@vger.kernel.org>; Wed, 25 Mar 2026 18:42:11 +0000 (UTC)","by mail-vs1-f41.google.com with SMTP id\n ada2fe7eead31-602903ad849so36153137.3\n        for <linux-gpio@vger.kernel.org>;\n Wed, 25 Mar 2026 11:42:11 -0700 (PDT)","from mail-vk1-f169.google.com (mail-vk1-f169.google.com.\n [209.85.221.169])\n        by smtp.gmail.com with ESMTPSA id\n a1e0cc1a2514c-951be162f25sm1013076241.5.2026.03.25.11.42.09\n        for <linux-gpio@vger.kernel.org>\n        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n        Wed, 25 Mar 2026 11:42:10 -0700 (PDT)","by mail-vk1-f169.google.com with SMTP id\n 71dfb90a1353d-5674d8be45eso127881e0c.1\n        for <linux-gpio@vger.kernel.org>;\n Wed, 25 Mar 2026 11:42:09 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1774464133; cv=none;\n b=LJmQqGw8tP8Ghob94soSgA8arRKglX26s5btf5LMgNI0dlRDY6cPXmaUAk0FaKTho0mupwOf98h9fgXzkwkApaZiDFODlEq+135KFnXP/+T3+cMqbXUxCRle0akROvhzU0gyyT2pcUPjgaBZ5ulI2UhVfRgf7hBl8C8wwNEkFlI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1774464133; c=relaxed/simple;\n\tbh=bfTeD36m7Ullk5L1jo6SH+GigHcnF1GoRgV9s3OSnFk=;\n\th=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:\n\t To:Cc:Content-Type;\n b=H8tiF8SDMYCsY2Ry5u8JLd2FtRU4aczCAGfifRnt/zszsA6i51hvpvYKCYKlG5nWSihxJWvp9yB+TBvgkI1jTS7hD/lqJMxjKf0EZLMbmCRbcfFp/LHOsqNyGbzPipM5V0dODBRC8l0wS2RUYUfMRknqdfR1HaMhbaoLaa/1J9o=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=linux-m68k.org;\n spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.217.41","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1774464131; x=1775068931;\n        h=cc:to:subject:message-id:date:from:in-reply-to:references\n         :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=aD3RRMKcnhLrwqe0WAwzPlfJXdwopk87davQxw2QDSM=;\n        b=W/RsJTJtC0gx+IUITU21J9B5TWES0dtf6D+HIPvRo07QWe6XyiW9mNpXgm5P0GnmPt\n         dG79IxRzDix9kDo0Q++d/tSkLm1NOpmLSmy2BVQpAEyxySLbluMGatJhcDDZTCEJtNhC\n         RV7M47hAIzlBEvcBI/dLI3DYxLHANjguJDRbE6FbzaMFmdd0Qckyd/B05dDeZBNVMzHX\n         DcdC5ywcL36agp34pT0xuydAn0AJW42FFtg4OiJ3vUXlBsCUGZlNuM2qDB+3qfwYIFjp\n         jY9+Y+xkZqZqXMh75oogyRCiwcUr5Est/fGQsfPwluGhxvOXOp5YQxj3o36cmeWGL9t2\n         ZGIA==","X-Forwarded-Encrypted":["i=1;\n AJvYcCVbtlDdv5APCvnEGdE6raCl/5YAIyzt4UBKj6DjJ5i1yQlkFpwz6FJ70WVSxaskMQV+COz2LC+3oKbb@vger.kernel.org","i=1;\n AJvYcCXg68OUJHwBuFYmIOlh0xgmMM0AuUVw5U5dGZdD0Qg19G9nvQKFDZRlfF7nwXRPPzJAyiiFV/gReLDL@vger.kernel.org"],"X-Gm-Message-State":"AOJu0YzS+PFBzHCRBpQdkAxz+EY6Le2Wq8dPzQwMkTENB/rF3ttLzB3q\n\tnzZK0PRLzm+2V/v625YSFzV0vIUgRGNtuEofI+5k0RcIpgoHHi/okMzJxw9t1BDTfe8=","X-Gm-Gg":"ATEYQzxB3z9RLtIb4aH3qz01gU9Gqdd+BUDyLA4MnVJm5Q2lwzZGn06u1eoMD9cyK7T\n\tfcjHvpOsBObK3wXz84X7fVsNX7RaK699FystaHofNZuYkTUNFNyT5WiafjO1yL/yZYRHRgufbbv\n\t+Ie0WiBCawqpdjotkA9EiNGyO33M3GL5z7uuaRiv2oXij6V19/MGliFAz8If2EUw6BIirbPb2Ve\n\tLdFIRxn+TFqOnJtU50TnxExssTpX2DpKngniZ8D/wLqNlzRO9Y2yxyH+ToIMl7K+kSGOyLyDO+U\n\tPWFbtoii+vEH9b1Cg0ACGm/438QbQwE92DEjTS4MMzSemM1malzaQyKsYvp2j9cn0pZx9WTEiul\n\tWPftEOt+80fE2j6MnzhUW5+U2JX7qoh0mq+tJth26k+PHmi0UMguk9o30IlQvPAeoOs8QvS/2ss\n\tM6xtL/CApa2ApQIiRegbQ3shDGM6QdCjJ2nH2cIqtyb40NGFy0eSLx32x78cFaXQga","X-Received":["by 2002:a05:6102:554b:b0:5ff:a16b:93f0 with SMTP id\n ada2fe7eead31-60387268e91mr2116354137.22.1774464130599;\n        Wed, 25 Mar 2026 11:42:10 -0700 (PDT)","by 2002:a05:6122:3387:b0:56b:5e7e:d3fa with SMTP id\n 71dfb90a1353d-56d21f56bcfmr2331636e0c.7.1774464129405; Wed, 25 Mar 2026\n 11:42:09 -0700 (PDT)"],"Precedence":"bulk","X-Mailing-List":"linux-gpio@vger.kernel.org","List-Id":"<linux-gpio.vger.kernel.org>","List-Subscribe":"<mailto:linux-gpio+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-gpio+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","References":"<20260325-gpio-hogs-multiple-v1-1-7e3a7347f0d6@oss.qualcomm.com>","In-Reply-To":"<20260325-gpio-hogs-multiple-v1-1-7e3a7347f0d6@oss.qualcomm.com>","From":"Geert Uytterhoeven <geert@linux-m68k.org>","Date":"Wed, 25 Mar 2026 19:41:57 +0100","X-Gmail-Original-Message-ID":"\n <CAMuHMdVpQ_HmqXqB=MwJJYbNKgNvrb0ZdbNbiiz=CXK1qECBEQ@mail.gmail.com>","X-Gm-Features":"AQROBzC5JiMRN7OZ7uNvlUBK6_mIDv8br2tHjFBjjLQcYFyaUf-7wpM6eZoCWUA","Message-ID":"\n <CAMuHMdVpQ_HmqXqB=MwJJYbNKgNvrb0ZdbNbiiz=CXK1qECBEQ@mail.gmail.com>","Subject":"Re: [PATCH] gpiolib: fix hogs with multiple lines","To":"Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>","Cc":"Linus Walleij <linusw@kernel.org>, Bartosz Golaszewski <brgl@kernel.org>,\n\tMika Westerberg <mika.westerberg@linux.intel.com>,\n\tAndy Shevchenko <andriy.shevchenko@linux.intel.com>,\n linux-gpio@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org","Content-Type":"text/plain; charset=\"UTF-8\""}},{"id":3669737,"web_url":"http://patchwork.ozlabs.org/comment/3669737/","msgid":"<CAMRc=MfHDVLE51WF9UdBbJOQ0mktO3tQYZ4=zXa6WPWV0bMq6Q@mail.gmail.com>","list_archive_url":null,"date":"2026-03-26T13:54:35","subject":"Re: [PATCH] gpiolib: fix hogs with multiple lines","submitter":{"id":92191,"url":"http://patchwork.ozlabs.org/api/people/92191/","name":"Bartosz Golaszewski","email":"brgl@kernel.org"},"content":"On Wed, Mar 25, 2026 at 7:42 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:\n>\n> Hi Bartosz,\n>\n> On Wed, 25 Mar 2026 at 11:18, Bartosz Golaszewski\n> <bartosz.golaszewski@oss.qualcomm.com> wrote:\n> > After moving GPIO hog handling into GPIOLIB core, we accidentally stopped\n> > supporting devicetree hog definitions with multiple lines like so:\n> >\n> >         hog {\n> >                 gpio-hog;\n> >                 gpios = <3 0>, <4 GPIO_ACTIVE_LOW>;\n> >                 output-high;\n> >                 line-name = \"foo\";\n> >         };\n> >\n> > Restore this functionality to fix reported regressions.\n> >\n> > Fixes: d1d564ec4992 (\"gpio: move hogs into GPIO core\")\n> > Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>\n> > Closes: https://lore.kernel.org/all/CAMuHMdX6RuZXAozrF5m625ZepJTVVr4pcyKczSk12MedWvoejw@mail.gmail.com/\n> > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>\n>\n> Thanks, that fixes the issue I saw on Marzen\n> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>\n>\n> > --- a/drivers/gpio/gpiolib.c\n> > +++ b/drivers/gpio/gpiolib.c\n> > @@ -938,12 +938,12 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)\n> >         struct fwnode_handle *gc_node = dev_fwnode(&gc->gpiodev->dev);\n> >         struct fwnode_reference_args gpiospec;\n> >         enum gpiod_flags dflags;\n> > +       const char *name = NULL;\n> >         struct gpio_desc *desc;\n> >         unsigned long lflags;\n> > -       const char *name;\n> > +       size_t num_hogs;\n> >         int ret, argc;\n> > -       u32 gpios[3]; /* We support up to three-cell bindings. */\n> > -       u32 cells;\n> > +       u32 cells = 0;\n>\n> Shouldn't the default be 2?\n>\n\nFor DT I suppose there's no real \"default\" but it does make sense to\nset it to 2 for the generic fwnode path.\n\n> >\n> >         lflags = GPIO_LOOKUP_FLAGS_DEFAULT;\n> >         dflags = GPIOD_ASIS;\n> > @@ -952,43 +952,21 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)\n> >         argc = fwnode_property_count_u32(fwnode, \"gpios\");\n> >         if (argc < 0)\n> >                 return argc;\n> > -       if (argc > 3)\n> > +\n> > +       ret = fwnode_property_read_u32(gc_node, \"#gpio-cells\", &cells);\n>\n> Should this call be protected by is_of_node(), like in the old code?\n>\n\nNot necessarily. We may end up using it with software nodes for\ninstance. I'd keep it global.\n\n> > +       if ((ret && is_of_node(fwnode)) || (!ret && (argc % cells)))\n> >                 return -EINVAL;\n> >\n> > +       num_hogs = ret ? 1 : (argc / cells);\n>\n> While you avoid modulo and division by zero due to the check for ret,\n> using a default would let you always validate argc against cells,\n> and remove the need for special casing num_hogs.\n>\n> > +\n> > +       u32 *gpios __free(kfree) = kcalloc(argc, sizeof(u32), GFP_KERNEL);\n>\n> kzalloc_objs()?\n>\n\nTrue.\n\nBart","headers":{"Return-Path":"\n <linux-gpio+bounces-34212-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-gpio@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=GD4HTdcA;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-gpio+bounces-34212-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"GD4HTdcA\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fhQVL6Rlvz1y1G\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 27 Mar 2026 01:03:38 +1100 (AEDT)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 98BBB3039EC9\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 26 Mar 2026 13:54:52 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id A4FEE231A23;\n\tThu, 26 Mar 2026 13:54:51 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 6611630216D\n\tfor <linux-gpio@vger.kernel.org>; Thu, 26 Mar 2026 13:54:51 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 088E4C2BCB1\n\tfor <linux-gpio@vger.kernel.org>; Thu, 26 Mar 2026 13:54:51 +0000 (UTC)","by mail-lj1-f177.google.com with SMTP id\n 38308e7fff4ca-38c26612508so7687341fa.3\n        for <linux-gpio@vger.kernel.org>;\n Thu, 26 Mar 2026 06:54:50 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1774533291; cv=none;\n b=EyWQSWhIFr9aVes6vzxcLoniHLya2gcNLlS/bo7VumPntqdRyCaA5W1FXI8hi6sso4CSk7inzj/r1Igvjm0nzSLYvH5SLMOCnaPLIB29NyLhztfe9Y95fQu+XPc/fMqCN2g61W/rTD1QtSA2PlXlDcy1SmA8r9PsET0x+zsJJAI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1774533291; c=relaxed/simple;\n\tbh=fXGs19NsXEECc/WRjysd6IHGu58ST8EfrQSfa0r89BE=;\n\th=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:\n\t To:Cc:Content-Type;\n b=b+8CgqyC4c+eHKMBdv9ySISyvFtOMm3NKBlmVKaYnDen7jvM2Uq0YV7Xa7zCSn0H5sDUjbhjtBMgB/s9NVLReqqq8PCVtXixpm0AxpPfE3PWnzoVQ5wIp7vtkV4OBeEL08rP62MQDisYDWGuubEP3LO0kLUnfeSgw2TvJ9J+Eb8=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=GD4HTdcA; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1774533291;\n\tbh=fXGs19NsXEECc/WRjysd6IHGu58ST8EfrQSfa0r89BE=;\n\th=References:In-Reply-To:From:Date:Subject:To:Cc:From;\n\tb=GD4HTdcAPNEvx4UFryBaPRKjsoPzWorP1w1Oy7bYY0VCOIhpTtUemMWjVutUHII5S\n\t o/7KNB9+WX5rDHYdTB+BMxM9IEAKJaf10qxKikv2WyiYuTfCe+x4Do486wePQi4l1i\n\t H00wmsP5eetU3AJHXmqpjIGhi/wC094/3nPnRyksNbABnL4FPjgq5BmnNfEZxOqhKe\n\t gA1bBDcqC6HnPZtgDp0KOk2uMeP7n/NpL4Vd+eB7Pj53jxDbtmHcoRFhfYb80laDUa\n\t 0CxfdKSGzwZY2Ito76rK7vj5idFK8YHsjRt8G04T0UPfWDGELqI5NgtULaB9v0LMyN\n\t qKBvpSGjJiL3A==","X-Forwarded-Encrypted":"i=1;\n AJvYcCU78kXwbbGAyZt6FNsLlMEHxDgcSg2r7DjiBZAgSGh1bl1uFttOP/YQDHxE7FXPmDTMc9cXDqCwi95P@vger.kernel.org","X-Gm-Message-State":"AOJu0YxIMOvllwy0iuE1bWeDk9EHmVH0nYV3TsAj1OybEMxN3fqsMgz1\n\t0St+FAepSubmJvXLatlq/a7+a8eaQvB71hHz6zKgHZVh+pM2dbaDzldBzFoU6jXR6V0jtsgLzCo\n\tQiUCdoZUNNFKT5r4grOs6NxuH2HD0HErX962/vBBGiw==","X-Received":"by 2002:a05:651c:e0a:b0:38c:6979:f76d with SMTP id\n 38308e7fff4ca-38c6979fd5dmr3438721fa.17.1774533289615; Thu, 26 Mar 2026\n 06:54:49 -0700 (PDT)","Precedence":"bulk","X-Mailing-List":"linux-gpio@vger.kernel.org","List-Id":"<linux-gpio.vger.kernel.org>","List-Subscribe":"<mailto:linux-gpio+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-gpio+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","References":"<20260325-gpio-hogs-multiple-v1-1-7e3a7347f0d6@oss.qualcomm.com>\n <CAMuHMdVpQ_HmqXqB=MwJJYbNKgNvrb0ZdbNbiiz=CXK1qECBEQ@mail.gmail.com>","In-Reply-To":"\n <CAMuHMdVpQ_HmqXqB=MwJJYbNKgNvrb0ZdbNbiiz=CXK1qECBEQ@mail.gmail.com>","From":"Bartosz Golaszewski <brgl@kernel.org>","Date":"Thu, 26 Mar 2026 14:54:35 +0100","X-Gmail-Original-Message-ID":"\n <CAMRc=MfHDVLE51WF9UdBbJOQ0mktO3tQYZ4=zXa6WPWV0bMq6Q@mail.gmail.com>","X-Gm-Features":"AQROBzC5m80_R-Bk5fk-q5rFjHQdTTDfMNWZx8NFfUlVLeYAQedrFeEd4N9-krQ","Message-ID":"\n <CAMRc=MfHDVLE51WF9UdBbJOQ0mktO3tQYZ4=zXa6WPWV0bMq6Q@mail.gmail.com>","Subject":"Re: [PATCH] gpiolib: fix hogs with multiple lines","To":"Geert Uytterhoeven <geert@linux-m68k.org>","Cc":"Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,\n Linus Walleij <linusw@kernel.org>,\n\tMika Westerberg <mika.westerberg@linux.intel.com>,\n\tAndy Shevchenko <andriy.shevchenko@linux.intel.com>,\n linux-gpio@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable"}}]