Received: by 10.213.65.68 with SMTP id h4csp1049866imn; Sat, 31 Mar 2018 17:43:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx49S9ibMc7253486BvrZzxtIBPI27R2EgL4cwiyDXZL1FAJmK0PpukvTGhHWer7HRY+xrjtu X-Received: by 10.101.76.129 with SMTP id m1mr2871869pgt.90.1522543416915; Sat, 31 Mar 2018 17:43:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522543416; cv=none; d=google.com; s=arc-20160816; b=PmIIxTqBl4GFTM0U+7kzL6be8+T15pof7ANAj7THyy87M0tyXgNfN5rV4FCS+CbXES I3QDrORfVfQCtAuxMp/4+ml1s+9dqHQZtkNAi/VsCxuiDMVSg3mGqwGa8T/IkPcZobAf PekfeENszjOTmQsKWzTr62x7QpbHkhT//o9XjOAMlEiMN4iYpt8xQ4mOXuUISn3aX6jH e1Oqs2BXFRwhNre2/0sUYii/CdjbASvIltOeDQENTnZBcDeBecysEY1oR2ZRQkFAIWvN OWIdTwmxROsrc10G/75dZ/0rKK+JksS1cuWesg2XMx9oczkwZtf3AzTXwyHPaRY0MJB7 y2oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=zUa/MkCZ+QWW4QJqnDLQW/QdhtZVcWymuLjd2Xyd6Ls=; b=tqHto0d/Ia3Ik/AgEs3LlmM0dgRmOPrq1LWcLDCauNdSSqDbFtZtwhPQFAsoq/bcE9 P40e6DMz2rTGie+1Y+o/sTmQtvIaF1n1lprgd4RuWAak9sQLJXfnws10gQdSOmNYkY9X Iu4ak55tVP4B4jiZy7IYDHljx8X3YYjG3h/tVnsJQNPlO8mKCC9foSn6BJmiryx14MC5 KNw/N6r9OpEizlCwU5VPOjiRs7tfb9VnrnEZ/cHxYm/ii1zdcriyPNWeLFTFVRqMclyW HUi++LpuP99UfHRfmuc7G1h4VoFNd53fZXObGKWvKoMjulNogckwYF6+SN3x9Vt1KqO9 y7lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vQLkHC+a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h5si998326pgq.162.2018.03.31.17.43.21; Sat, 31 Mar 2018 17:43:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vQLkHC+a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752919AbeDAAmJ (ORCPT + 99 others); Sat, 31 Mar 2018 20:42:09 -0400 Received: from mail-yb0-f177.google.com ([209.85.213.177]:37349 "EHLO mail-yb0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751163AbeDAAmG (ORCPT ); Sat, 31 Mar 2018 20:42:06 -0400 Received: by mail-yb0-f177.google.com with SMTP id u5-v6so4064744ybf.4; Sat, 31 Mar 2018 17:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zUa/MkCZ+QWW4QJqnDLQW/QdhtZVcWymuLjd2Xyd6Ls=; b=vQLkHC+azGOpC+NpjpDglgQrmYEg8QCH3MMQ9FLMfLTfxqWFwxFbVcs1N295f8Z3Sf IJk045lMKkgWK8xNQnTSfZUEcKAqRRfUepQAwXSLKePYCEWkjOQtLEuhlsYbeKoLPz4l YjtmCnlb9oI8m/h7EfAuHRCEsuMzPgPwUEeOhrvrZgLzM6hDebOyYWwWgk3HxM3C8Eqd mDAJE40fMlJmWZqNpFjm1MV+0Z7bIbYxW3GrNwJ3ilUviOGzjL7pTHK2P66ufiZJt4Wf 1R20gVAPfdJ/3o4JJN2EAt8ybjEaScZEuYd49m/28FZXWvrd1T0xzz0SJKCIlKshHndZ 5IWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zUa/MkCZ+QWW4QJqnDLQW/QdhtZVcWymuLjd2Xyd6Ls=; b=pCclJI5dd9rFw4wqJ1iJZJxVuRaNx6R5MBvTQfksv0XDyrfQnUqwq8DSsGGdfmhFzG MJ6eodjp4AgmBdSBMluMeK/CV6TASI5Tnb5ZhkG3nBnPPY+BteAje/ihwzRQLGbP2pvb HyyvoNHDBVQtPhhvdKARfiAIRNcJ82bkjMW8+7XuomCOUMxmHFsreasI8JVLBfClP4fh 0UZGGXqto7zF0YVkPYeZTbfZ5WMNvQwMLwwGUcn33PBu6tCEZZqPiX3XYJb018D+6ogB lCRKlJDneJMX/+WPA+aAAI9AsDiSIaBiY3q7WL6hPb3gY3wSDNUHPzIHIhF1IiXr9MkD LUXA== X-Gm-Message-State: AElRT7FF08g++ZVvJACIY39mrvq0fnoUgYrhsKIyQPmAK6h17qi7zkQN TiYAGOoA+CWvj+4vNg+tQTGQ0g== X-Received: by 2002:a25:2489:: with SMTP id k131-v6mr2364554ybk.182.1522543325878; Sat, 31 Mar 2018 17:42:05 -0700 (PDT) Received: from sophia ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id d7sm4541946ywa.42.2018.03.31.17.42.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Mar 2018 17:42:05 -0700 (PDT) Date: Sat, 31 Mar 2018 20:41:54 -0400 From: William Breathitt Gray To: Jonathan Cameron Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, benjamin.gaignard@st.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 1/8] counter: Introduce the Generic Counter interface Message-ID: <20180401004154.GA21955@sophia> References: <20180324173358.571e2fd8@archlinux> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180324173358.571e2fd8@archlinux> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 24, 2018 at 05:33:58PM +0000, Jonathan Cameron wrote: >On Fri, 9 Mar 2018 13:42:23 -0500 >William Breathitt Gray wrote: > >> This patch introduces the Generic Counter interface for supporting >> counter devices. >> >> In the context of the Generic Counter interface, a counter is defined as >> a device that reports one or more "counts" based on the state changes of >> one or more "signals" as evaluated by a defined "count function." >> >> Driver callbacks should be provided to communicate with the device: to >> read and write various Signals and Counts, and to set and get the >> "action mode" and "count function" for various Synapses and Counts >> respectively. >> >> To support a counter device, a driver must first allocate the available >> Counter Signals via counter_signal structures. These Signals should >> be stored as an array and set to the signals array member of an >> allocated counter_device structure before the Counter is registered to >> the system. >> >> Counter Counts may be allocated via counter_count structures, and >> respective Counter Signal associations (Synapses) made via >> counter_synapse structures. Associated counter_synapse structures are >> stored as an array and set to the the synapses array member of the >> respective counter_count structure. These counter_count structures are >> set to the counts array member of an allocated counter_device structure >> before the Counter is registered to the system. >> >> A counter device is registered to the system by passing the respective >> initialized counter_device structure to the counter_register function; >> similarly, the counter_unregister function unregisters the respective >> Counter. The devm_counter_register and devm_counter_unregister functions >> serve as device memory-managed versions of the counter_register and >> counter_unregister functions respectively. >> >> Signed-off-by: William Breathitt Gray > >Hi William, > >I would leave the existing drivers where they are until you are ready >to convert them. I.e. Do the moves as separate patches from this one >as it just adds noise here and they aren't ready immediately. > >The externs in the header add code for no benefit and make it hard >to align the parameters nicely. I would drop them all. > >Few other minor bits and bobs inline. There is a lot of 'automatic' >cleanup in here, but I think you have missed a few cases where the >attribute element hasn't 'yet' been added to the list. (I may be >missing something) > >Fundamentally looks good though. > >Jonathan Hi Jonathan, Most of these are simple cleanups so I don't anticipate any trouble incorporating them in version 6 of this patchset. :-) Regarding the "name" strings allocated throughout, these are freed later in the free_counter_device_groups_list function (which is called on error codes passed up). This unwinding is hard to follow so I think I'll refactor these code blocks to perform frees closer to the relevant memory allocations; despite the additional code, I expect the clearer logic will aid future debugging endevors. Some minor comments follow. William Breathitt Gray [...] >> +static int counter_counts_register( >> + struct counter_device_attr_group *const groups_list, >> + const struct counter_device *const counter) >> +{ >> + const size_t num_counts = counter->num_counts; >> + struct device *const dev = &counter->device_state->dev; >> + size_t i; >> + struct counter_count *count; >> + const char *name; >> + int err; >> + >> + /* At least one Count must be defined */ >> + if (!counter->counts || !num_counts) { >> + dev_err(dev, "Counts undefined\n"); >> + return -EINVAL; >> + } >> + >> + /* Register each Count */ >> + for (i = 0; i < num_counts; i++) { >> + count = counter->counts + i; >Is counter->counts ever set anywhere? This is the array of struct counter_count defined by the consuming driver. The preceding null checks are sanity checks -- drivers should always set the counts and num_counts members before calling the counter_register function. Since drivers are required to set these members, perhaps I should remove the sanity checks as superfluous since it is unlikely an unset counts or num_counts member would pass unnoticed by driver authors, reviews, and maintainers. Would it make sense to remove this conditional? >> +/** >> + * devm_counter_register - Resource-managed counter_register >> + * @dev: device to allocate counter_device for >> + * @counter: pointer to Counter to register >> + * >> + * Managed counter_register. The Counter registered with this function is >> + * automatically unregistered on driver detach. This function calls >> + * counter_register internally. Refer to that function for more information. >> + * >> + * If an Counter registered with this function needs to be unregistered >> + * separately, devm_counter_unregister must be used. >> + * >> + * RETURNS: >> + * 0 on success, negative error number on failure. >> + */ >> +int devm_counter_register(struct device *dev, >> + struct counter_device *const counter) >Where possible align with the opening bracket. >checkpatch.pl --strict (but take into account some of the warnings will >be silly so don't fix them all). I'll try this out and see how it looks with everything aligned to the opening bracket. One worry I have is in the case of parameter definitions that are wide such as in the counter_attribute_create function, which has two function pointers as parameters. In cases like these, aligning to the opening brackets would produce very vertical parameter lists. Should I mix and match, i.e. align to the opening brackets for some functions while permitting others to follow a single tab alignment, or would it be better to commit to a single alignment style throughout the entire file? [...] >> +/** >> + * struct count_read_value - Opaque Count read value >> + * @buf: string representation of Count read value >> + * @len: length of string in @buf >I wonder if you are ever going to want to have in kernel consumers. >Using strings this early level would make that hard. > >I'm also unclear on why it makes sense to do so given count >is always an integer - Potentially things could get interesting >when you are either signed or unsigned and matching the number of >bits (s16, u16 or similar). > >Given this is in kernel interface though, nothing stops you modifying >it later if you change your mind about this. Yes, the idea here is to keep it opaque so that the implementation can change independently without requiring changes to consuming drivers. Although counts right now are integers, there may be drivers in the future which require another type such as floating-point, so I want to keep it generic enough to support those type of devices in the future without causing drastic changes to the existing drivers that depend on the Generic Counter API. Since the struct count_read_value is opaque, the decision to use strings here was for my own convenience since I can pass the buf member directly to the relevant attribute show and store functions; this implementation can easily change for any future requirements. [...] >> +enum signal_value_type { >> + SIGNAL_LEVEL = 0 >This one surprised me. Only one option? At present it does seem silly to declare an enum for a single option, but I want to keep the paradigm established by enum count_value_type consistent with an enum signal_value_type. Currently, only the 104-QUAD-8 driver provides a signal_read callback, so we only have the SIGNAL_LEVEL type defined to represent a Signal low/high state. Since the Generic Counter paradigm is flexible enough to represent Signals of various types, I expect future counter driver patches to add their signal types as new enum signal_value_type options as required. Although, I anticipate SIGNAL_LEVEL serving the majority of counter devices just fine; I don't see many devices requiring Signal representations other than low/high.