Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp325779lqs; Thu, 13 Jun 2024 11:04:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUB/BjIhmwbJw8HXM33C+VLfg9gJSxiUww58ZO4aToztK5m48swfgUIrxLcsNgSqgbnDs7ssP6QfY47clKK+ZZuOyU6g68Z5eez5oVuuQ== X-Google-Smtp-Source: AGHT+IHdZOXT/33I8ZgkOaEk3VZA/dEXoZnlustj/PqPZfMBCIBd7QqgR2AGB36hHt7xNGpHAHlC X-Received: by 2002:a17:907:c713:b0:a6f:61c7:dead with SMTP id a640c23a62f3a-a6f61c7df96mr17815366b.17.1718301850138; Thu, 13 Jun 2024 11:04:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718301850; cv=pass; d=google.com; s=arc-20160816; b=JqNPtspWwJeCdlWg0HxSrGkykCn1/vVtLjEV0wBua2RgDUsMPK1rgZ//iRGOuJGGep wDi/3scpW3vr5NApg50MBgVzpSA3xiPo5yMR9vt4WWx9L3TR4yotokSkA6a+RAgjYfDU cHj/cQhNcY7P39FTXmqQjMKGAsK2ADz6rHJWwxZQ7DLQgVA+s69E7snG65DcYCDHN8rh v89ed5mp/axN0cdYmVdw8oyFsrSknc0xWr8Zhl8lCZV6q6Xs0BSoZDWduBDWHOt54zWw DQFKsAfp01hLDQogT/TQ6bhx5gwIw7/o8VbZsBobbaZo2QBYbOCxqTjH0oWFY+Sd8Atp 0Jpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=mqUSRrPlfqU4kfBGlHEIAysFGYiaLQcWciUI9mtNYcc=; fh=/U8HYw0Bi+qGWi1Q2mIvbaoQ4ROK7iGz1inuc5ieBWU=; b=xDo3cst9xBakeeLB8FRHUS1S5jXVLyly2OoffxkVxNddjOKN+G+DnkWc50QoChfXrF acKlW1GPAsERzOFtCrL6dNIbNCZVPIpVTKlwRfrUA+OhT9LZJF1v6vkEm0ejKUZ7xzzW UvOjMpFBkM819aEjZWYRqFKdFrfXxKiZxsxDeMQ6CWsGDFZBJTNL+x3BzPNIO9CCbeym CkX8I5s5qKkwoZ2+aP2zrmpLfBC+8tSPcV3PUVa6qoqdxswncotnTNqhzVaFygAKT/Sr fUBqPTZzv59PhUK7Vdec8ke1JPNWGbmnspvmW/Z+4hpMQWHXuFTZ71N54bWy+o+THVHc ZEew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OP1tVlse; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-213791-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56d4d19fsi88559266b.246.2024.06.13.11.04.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 11:04:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213791-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OP1tVlse; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-213791-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A5F901F22845 for ; Thu, 13 Jun 2024 18:04:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9F2C14A602; Thu, 13 Jun 2024 18:04:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OP1tVlse" Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FD1712CD8F; Thu, 13 Jun 2024 18:03:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718301841; cv=none; b=SSovcDUUTO4UHVwIzert4VJJFEtUjQgqjBa6wU4fIGWrowIRZMR8B0T3ien+DLpld0lz32vbVF5I3Ly5tWsI8Wyc58eDjTSZkU866T9qP5JGvaaKo1UsTLy8S9g0u1ewsGEc9NGq8gnOgnZTvIaAJ61JFYMbwwoAbw76o6/2GcM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718301841; c=relaxed/simple; bh=bAI1JUMbvq/VJSL8Scl3Z4BW4+S1/r6U8oGPWP6QY1g=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=L8cgA6piAiE28UUboSvgsm7zT/yoAIsG0W7uF41BHasSTE9oZZx8PXhayujYLkUwp23V1UaWCkYLWlR5XC4g7di8lwcUO2gl2/dOMTAKmavHZDAb7I6Ke23jSyHQ+a5dZRNy7PsFNZPCa06hLrBG2G/FbJ7M7d/0OR5+Bmrv7e8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OP1tVlse; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a6f176c5c10so168336766b.2; Thu, 13 Jun 2024 11:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718301838; x=1718906638; 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=mqUSRrPlfqU4kfBGlHEIAysFGYiaLQcWciUI9mtNYcc=; b=OP1tVlsept9svBRw97NUV1DDt4qzHkp2aXl+oAA0A/k30QMfADIPrXwVhYrJW5hdlX oky3sJcFsWj52x41jEPlj3uSOOolNBAO32MDlitzOJKAKYtFEc5iIxch1XZNq++nEXYX 0M4RcGnTqRYuyEXjU/So8Tzef3ZuBeM1wg1wPbIQAWFhFBvPQVepWefsLiEl5K24WuV5 +ouIPtIuWH2H6KcVph9LMWHCsVimD8etfY0DAYxmUNutb6nih/z+A5vq3kh2vQl5y1gH RwI7z3NTH6seYE59KG05jZSvy+RyC87fafvyAxvARW6pgnCThVkU4i5FCytry/nIjND1 +EYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718301838; x=1718906638; 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=mqUSRrPlfqU4kfBGlHEIAysFGYiaLQcWciUI9mtNYcc=; b=DHt0me8t4RV6qJoeC4ZbpBHVqk/GNWnRr6DvWu+hq1A1Wv7FUQ5njIKo4VvtE5nnTU y/LxWL8L88eZp7IUXWHmXKzF4hY5Ziqe9FiQkB528WSCTmsijIDtSXlxR+dUbln8wzFK clj3JeXyXuFHjVSJK+yOcEwSSDCPcucOFXCDh1ESCOF9M4ZGTM+IPMp6aRe5YyM3uCx8 br5lCOKB0RjMPBumG1VcEiqCNd9DNWjAmPkiS4LjXGcKJuhrzuN8N7upTIeGDdTAT5pq JEsJOq9bFjj/zO5SaoSKNmM7goP0OwzWlCJmjJoDCxV1D08ILElOVAoKBlkWir4U0ec1 d+kg== X-Forwarded-Encrypted: i=1; AJvYcCULcz80dUHRInQOi+9blJGCHgUJjIEtEI7ehibhAgk8n841gmD6Vj/FMOgzTKtgcTnk0UzkEgEEZCgqTB8+TwxVmH04GQuJbwTeGUT6HJrqF0C3nefPTdTKnThvCj8qD2Gc0fhbaIhvRg== X-Gm-Message-State: AOJu0YwmI5V4m+bbSvLAJqIrC+fCGpfzxt8F5DwzPkc1P4vAhcKJBeRA yZeEMZqPkCtQQqH7UMQcOF1cUH96me4InosKmb2Ix5p8v7hnTyWdGWsXpJgw7NI8qolE/fAHaUG MZxZ2cloj/VrFp8tP4y2hqAOvFUBh3GFm41OIJQ== X-Received: by 2002:a17:906:34d1:b0:a6f:49eb:31a5 with SMTP id a640c23a62f3a-a6f60deaacemr31567866b.77.1718301838122; Thu, 13 Jun 2024 11:03:58 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240527144054.155503-1-brgl@bgdev.pl> In-Reply-To: From: Andy Shevchenko Date: Thu, 13 Jun 2024 20:03:21 +0200 Message-ID: Subject: Re: [PATCH v7] gpio: virtuser: new virtual driver To: Bartosz Golaszewski Cc: Kent Gibson , Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jun 12, 2024 at 8:38=E2=80=AFPM Bartosz Golaszewski = wrote: > On Mon, Jun 10, 2024 at 4:57=E2=80=AFPM Andy Shevchenko > wrote: > > Mon, Jun 10, 2024 at 03:22:32PM +0200, Bartosz Golaszewski kirjoitti: > > > On Wed, May 29, 2024 at 11:00=E2=80=AFPM Andy Shevchenko > > > wrote: > > > > Mon, May 27, 2024 at 04:40:54PM +0200, Bartosz Golaszewski kirjoitt= i: ... > > > > > +static ssize_t gpio_virtuser_sysfs_emit_value_array(char *buf, > > > > > + unsigned long *= values, > > > > > + size_t num_valu= es) > > > > > +{ > > > > > + ssize_t len =3D 0; > > > > > + size_t i; > > > > > + > > > > > + for (i =3D 0; i < num_values; i++) > > > > > + len +=3D sysfs_emit_at(buf, len, "%d", > > > > > + test_bit(i, values) ? 1 : 0); > > > > > + return len + sysfs_emit_at(buf, len, "\n"); > > > > > > > > Why not use %pb? > > > > > > Because it outputs hex? I want to output binary, can I do it? > > > > But why do you need that? You can also print a list of numbers of bits = that > > set (%pbl). > > > > We have a few ABIs in the kernel that works nice and people are familia= r with > > (CPU sets, IRQ affinity masks, etc). Why to reinvent the wheel? > > If I see "11001011" as output, I can immediately convert that to pins > in my head. If I see 0xcb, I need to use a calculator. From my experience I see the opposite, as the hex values are condensed, it will be easy to get lost in binary > 8 bits. Despite that, I am really against Yet Another Parsers in the kernel. Here I do not see a good justification for one more. As I pointed out the kernel has very known bitmap ABIs that users are familiar with. Are you creating a driver for yourself or for a wider audience? > > > > > +} ... > > > > > +static int gpio_virtuser_sysfs_parse_value_array(const char *buf= , size_t len, > > > > > + unsigned long *val= ues) > > > > > +{ > > > > > + size_t i; > > > > > + > > > > > + for (i =3D 0; i < len; i++) { > > > > > > > > Perhaps > > > > > > > > bool val; > > > > int ret; > > > > > > > > ret =3D kstrtobool(...); > > > > > > kstrtobool() accepts values we don't want here like [Tt]rue and [Ff]a= lse. > > > > Yes, see below. > > > > > > if (ret) > > > > return ret; > > > > > > > > assign_bit(...); // btw, why atomic? > > > > > > > > > + if (buf[i] =3D=3D '0') > > > > > + clear_bit(i, values); > > > > > + else if (buf[i] =3D=3D '1') > > > > > + set_bit(i, values); > > > > > + else > > > > > + return -EINVAL; > > > > > > > > > + } > > > > > > > > BUT, why not bitmap_parse()? > > > > > > Because it parses hex, not binary. > > > > So, why do we reinvent a wheel? Wouldn't be better that users may apply= the > > knowledge they are familiar with (and I believe the group of the users = who know > > about bitmaps is much bigger than those who will use this driver). You see, you ignored this comment. > > > > > + return 0; > > > > > +} ... > > At bare minumum you can reduce the range by using kstrtou8(). > > As opposed to just checking '0' and '1'? Meh... Okay, can you explain why you need to take bigger numbers when it's going to be used only in a very reduced range? Esp. negative ones. Whatever, your choice. ... > > > > > + int i =3D 0; > > > > > > > > Why signed? And in all this kind of case, I would split assignment.= .. > > > > (1) > > > > > > > + memset(properties, 0, sizeof(properties)); > > > > > + > > > > > + num_ids =3D list_count_nodes(&dev->lookup_list); > > > > > + char **ids __free(kfree) =3D kcalloc(num_ids + 1, sizeof(*i= ds), > > > > > + GFP_KERNEL); > > > > > + if (!ids) > > > > > + return ERR_PTR(-ENOMEM); > > > > > + > > > > > > > > To be here, that the reader will see immediately (close enough) wha= t is the > > > > initial values. Moreover this code will be robuse against changes i= n between > > > > (if i become reusable). > > > > > > Sorry, I can't parse it. > > > > I meant to see here > > > > i =3D 0; > > > > instead of the above (1). > > Why? I see no good reason. There are two: 1) readability as explained above; 2) maintenance. The second one is good in case the same variable (that's the very often case for such as "i" is going to be reused in the future by some new code. But okay, in this case you probably will be the only one for maintenance. > > > > > + list_for_each_entry(lookup, &dev->lookup_list, siblings) > > > > > + ids[i++] =3D lookup->con_id; --=20 With Best Regards, Andy Shevchenko