Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5400390rdb; Wed, 13 Dec 2023 07:40:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVm/aoPJCTAixu89VHQC6TpDSfp/GRpgbSmcQ9RhQMaOQaOA9HKGG56vyy3HlCSYmK6fC3 X-Received: by 2002:a05:6a20:9390:b0:18f:c737:1c9f with SMTP id x16-20020a056a20939000b0018fc7371c9fmr9999305pzh.5.1702482045396; Wed, 13 Dec 2023 07:40:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702482045; cv=none; d=google.com; s=arc-20160816; b=Thu9zGRtDlsV6bomMepEtJBC3T5tRAV3g7tFUhWikoh0L7U4bdH9jjbMBLf8d9oNOF omUPMN1wZ9oD34z0z9PKV3qLjwkvTAc/FVcXoKFsHk3bqk2zMTWSqi7l+3u/MPExG0Nz geN8SNvwdLJqvSyRziqf1IQG8o4SGzQAPaBqUMReXUTSpNCPxek6BC/nRUB+j1bp6UOY jsXNsaMWzN3hvsU3uGZlzpob+qpo5PpnZ+RDHiABUkDQAm+jfv8NO8kAO92Pzg2w76ay +rzwhQ1IH1zmgFWgtip6WnOqxCGMb/6lTSddKcVdEmgtay9sDyh+oYJPvV/t3x0nKjv+ EvYw== 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=JvB5R6Qps8EFTNLIHUkdyYAJKBgwPtcunbgfuEeoU6g=; fh=LBhGixWNRo11MyGXiSWGCjYvem55ULBjnOqEhpMVKoE=; b=G9yervmcZ/z8cVbKHcV22RQ+EveF3A3izsikLY1eyflXXxRxGzAgy3FOBWD8hrDpwt UPJn8/1IwvA4t3y9McBONVrVaeOnOiV8nJH7lTcWSYmWc6bSYxRnGD/Sd5lPc1b1nOVi bbkIGTuEwzpjepjMrtukwFW5x3EZCXTnVE0EZ6abSCbqfXwwJUyZkRoxXBHp/5puuycj hRiqMBwovoSBHoaoYnEWYA43l9o3IiHAFKm5AwKRUqm5mpK2dCPMS7XFysOCoX7V3WL6 /YXrmdPvnzygJs+Rp6Bko4XSeSAf+fvZvz4rw9N9lVEBgrzPT7RW4tp02SZu3yu3bZZP Cekg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=GvmWxVnO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id kp8-20020a056a00464800b006cddd0d9820si9637335pfb.72.2023.12.13.07.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 07:40:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=GvmWxVnO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id ACEE58041EA2; Wed, 13 Dec 2023 07:40:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442221AbjLMPkU (ORCPT + 99 others); Wed, 13 Dec 2023 10:40:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442176AbjLMPkS (ORCPT ); Wed, 13 Dec 2023 10:40:18 -0500 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 199C3BD for ; Wed, 13 Dec 2023 07:40:24 -0800 (PST) Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6d9dc789f23so4923617a34.3 for ; Wed, 13 Dec 2023 07:40:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1702482023; x=1703086823; 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=JvB5R6Qps8EFTNLIHUkdyYAJKBgwPtcunbgfuEeoU6g=; b=GvmWxVnOLak+XMPO+ggLEdSlED6JE/z2uvp2PXGaTAYYoaDmaYvqRSeOJJUpEJR+ZL HQ2IYp17ZbY2ziLW9uwZpr1T6UhWnRftuTm1UszZUfST35zEiFtAGBHWY/11hAEtqNtZ 8Rx5x5ZpuvkbQbillGCUvnvwl0NZ2v71FakrXYGsAaOE3pV2cnMnGP+diFYjzBg7MX1l r/5qrliYBvl5ZIrPsHTjIt9jnckGfdYACvUkJPzdnvmwKT5/VlO5RY8XmMFb34lEeddj G2i1AwFtEaDHuzD29V3OCO8s+/QdpANgpLPC6SspD53QmgFUXio2r1P0NFVh9FH6Suyp 66ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702482023; x=1703086823; 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=JvB5R6Qps8EFTNLIHUkdyYAJKBgwPtcunbgfuEeoU6g=; b=AzGLJ10TADPqi44WrhXQFXtOpTB4jrgR9PpNHBjQoPhgpglAIe2qW96RCYWAerkR+6 CG/T5PvhvBB7GymL/QbAxy+iZagBoDwVGM3j5l9/UKmJZQ+UKPkEQjg6AgANXesfp1sJ zdfjqYFW/HsoBH867J+d2xHIR08f5PnVIAvDPqcwWght3miQi5dDhCcryrLIOggEPAcK +m/wWzPIESnGK9JGyR8vDxrUg0ulTwZN/FnhhVG05MFiBwhDk6894kvPCJR4ifz/1xxV okLNakTQhiklbbBgCUoqCeG+jSCSmIzefIK4MkkfNhyOn6VNlZ0syRUwN6zKmScJd0lv LKyQ== X-Gm-Message-State: AOJu0YwFjHnSPy/lygsVc2m4k8bNzXPbUiqKjxFdAAwQ9WRGQ6gSp6zU MqysIZsMv9nDjApmVOoOP+ObE/c3QZbYer87rH4IRA== X-Received: by 2002:a9d:5615:0:b0:6da:bc7:d11d with SMTP id e21-20020a9d5615000000b006da0bc7d11dmr4830623oti.52.1702482023371; Wed, 13 Dec 2023 07:40:23 -0800 (PST) MIME-Version: 1.0 References: <20231212054253.50094-1-warthog618@gmail.com> <20231212054253.50094-2-warthog618@gmail.com> In-Reply-To: From: Bartosz Golaszewski Date: Wed, 13 Dec 2023 16:40:12 +0100 Message-ID: Subject: Re: [PATCH 1/4] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc To: Kent Gibson Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linus.walleij@linaro.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 13 Dec 2023 07:40:42 -0800 (PST) On Wed, Dec 13, 2023 at 3:27=E2=80=AFPM Kent Gibson = wrote: > > On Wed, Dec 13, 2023 at 03:54:53PM +0200, Andy Shevchenko wrote: > > On Tue, Dec 12, 2023 at 01:42:50PM +0800, Kent Gibson wrote: > > > Store the debounce period for a requested line locally, rather than i= n > > > the debounce_period_us field in the gpiolib struct gpio_desc. > > > > > > Add a global tree of lines containing supplemental line information > > > to make the debounce period available to be reported by the > > > GPIO_V2_GET_LINEINFO_IOCTL and the line change notifier. > > > > ... > > > > > struct line { > > > struct gpio_desc *desc; > > > + struct rb_node node; > > > > If you swap them, would it benefit in a code generation (bloat-o-meter)= ? > > > > Didn't consider that placement within the scruct could impact code > generation. > Having the rb_nodes at the beginning of struct is preferable? > I suppose it has something to do with 0 offset when using container_of(). Not sure if that really matters though. > > > }; > > > > ... > > > > > +struct supinfo { > > > + spinlock_t lock; > > > + struct rb_root tree; > > > +}; > > > > Same Q. > > > > Same - I tend to put locks before the field(s) they cover. > But if the node being first results in nicer code then happy to swap. > > > ... > > > > > +static struct supinfo supinfo; > > > > Why supinfo should be a struct to begin with? Seems to me as an unneede= d > > complication. > > I think we should keep it as a struct but defined the following way: struct { spinlock_t lock; struct rb_root tree; } supinfo; > > Yeah, that is a hangover from an earlier iteration where supinfo was > contained in other object rather than being a global. > Could merge the struct definition into the variable now. > > > ... > > > > > + pr_warn("%s: duplicate line inserted\n", __func__= ); > > > > I hope at bare minimum we have pr_fmt(), but even though this is poor m= essage > > that might require some information about exact duplication (GPIO chip = label / > > name, line number, etc). Generally speaking the __func__ in non-debug m= essages > > _usually_ is a symptom of poorly written message. > > > > ... > > Yeah, I wasn't sure about the best way to log here. > > The details of chip or line etc don't add anything - seeing this error > means there is a logic error in the code - we have inserted a line > without erasing it. Knowing which chip or line it happened to occur on > wont help debug it. It should never happen, but you can't just leave it > unhandled, so I went with a basic log. > We should yell loudly in that case - use one of the WARN() variants that'll print a stack trace too and point you to the relevant line in the code. > > > > > +out_unlock: > > > + spin_unlock(&supinfo.lock); > > > > No use of cleanup.h? > > > > Again, that is new to me, so no not yet. > Yep, please use a guard, they're awesome. :) > > ... > > > > > +static inline bool line_is_supplemental(struct line *line) > > > +{ > > > + return READ_ONCE(line->debounce_period_us) !=3D 0; > > > > " !=3D 0" is redundant. > > > > I prefer conversion from int to bool to be explicit, but if you > insist... > > > > +} > > > > ... > > > > > for (i =3D 0; i < lr->num_lines; i++) { > > > - if (lr->lines[i].desc) { > > > - edge_detector_stop(&lr->lines[i]); > > > - gpiod_free(lr->lines[i].desc); > > > + line =3D &lr->lines[i]; > > > + if (line->desc) { > > > > Perhaps > > > > if (!line->desc) > > continue; > > > > ? > > Seems reasonable - I was just going with what was already there. > > > > > > + edge_detector_stop(line); > > > + if (line_is_supplemental(line)) > > > + supinfo_erase(line); > > > + gpiod_free(line->desc); > > > } > > > } > > > > ... > > > > > +static int __init gpiolib_cdev_init(void) > > > +{ > > > + supinfo_init(); > > > + return 0; > > > +} > > > > It's a good practice to explain initcalls (different to the default one= s), > > can you add a comment on top to explain the choice of this initcall, pl= ease? > > > > Not sure what you mean. This section used gpiolib-sysfs as a template, > and that has no documentation. > > > > +postcore_initcall(gpiolib_cdev_init); > > > > Thanks for the review - always instructive. > > Cheers, > Kent. Bart