Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp75686pxu; Wed, 14 Oct 2020 20:50:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjHYjaO7RvU+P440xpryNxj7SebFibRpCmk1XuqomP/Ss1jpsJ7spHiAkp9Cn/NZOtYkQh X-Received: by 2002:a17:906:fcae:: with SMTP id qw14mr2392984ejb.537.1602733833753; Wed, 14 Oct 2020 20:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602733833; cv=none; d=google.com; s=arc-20160816; b=GJZexCsqGjtNeMsjbQef73pjqBIeVT7rSr78WKyrj8cMMCpncwhPx8ynHENkCCtVWI hr9mrPseYPY/8i5bor/nAYRr8bOO2s0ewCjJvhznh7gCQIOeOn9kmW6Lmfs+qzOMtHcC rETRih0ltv+qKBdydjsZmzYAc9bIzHBJ0CRiHebeHC/5SjgEDSGBKk8vinwlAXgZbCos 5I6Wpy8o6HsSlhiyyf1rPr7KVxi+sWIfMMZZ7hdQo657Y1hXArVtXn/JTsqGUHKUaJE4 HJvzjg0+Qch2ZnaESaMcqZwrreMyMTXxf0D33u9zeHmdv2FdM0b73UGcVUyUm4PtGReV lHrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=gp9MgJ2x0h6hvVzIBbZuzEuotuQRfMr9VA1l8XSMkK0=; b=cjYg7ufCAxLsX4ZGmG6CkpKMLBxdocbk62bzci+VAe/oux0tL2/UnRHNl4viXs5qi2 lVi9iE9HVi2OYPUWzsXW8nZfbwO9suXtr1FyYfhHWlATQTjVBZ0taiNq49IT0zERl8Jk hJcPGl2TeC8i15uxARO9GSPkGBz09MpGVn2ne4DoUcYj/CUIso1VBQDT7TDpi/5mmK1M CRdxD3M9yRYwDJL4TYz7En/BaVx/tlL1wxvzDazGoxrHDL+j6AJRzLmEhkItPAOVa12p S6RwCrUOeii+ofyZJMg1Ol5sWpBZjfU4rkGERhB/eVXzWVLg/gLfkkJsncU5uARztGt5 e7iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=qQrq345Z; 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 bh20si1208251ejb.294.2020.10.14.20.50.11; Wed, 14 Oct 2020 20:50:33 -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; dkim=fail header.i=@lechnology.com header.s=default header.b=qQrq345Z; 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 S2388914AbgJOBir (ORCPT + 99 others); Wed, 14 Oct 2020 21:38:47 -0400 Received: from vern.gendns.com ([98.142.107.122]:34312 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388471AbgJOBir (ORCPT ); Wed, 14 Oct 2020 21:38:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gp9MgJ2x0h6hvVzIBbZuzEuotuQRfMr9VA1l8XSMkK0=; b=qQrq345ZOK8Aff+jHXcAfMtzE8 a7tu/sNjPjlU4toQVoA9SRMyRUOke2bm6M9BUy5cjWSIaU+C2gOqw48Ci7tsmf4smQMBZN3KhyoaW A83NcZVVWodBBsvqfTGwOlpTBsQWqt2dVwwauHgWTBcMKJX3SjK0FyjSTjCaloJ6PVFQwobtJXR5S G3eCRiqBclN4S3ZKXC4dxjJIryzrZwJKvd3YeO56NheG/pz/ITDtMaZGgQqR2BwGvSfYLCgz/tMki lzyzqXEdMgzQXx4+FH6Q9lp4tx2D9nyOyROt8sCuu73z11JCUBP7/iqKPLYtwWDCheoOufjRRZ0+c SMYvIXXQ==; Received: from [2600:1700:4830:165f::19e] (port=54538) by vern.gendns.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1kSsE6-0004Vi-DK; Wed, 14 Oct 2020 21:38:42 -0400 Subject: Re: [PATCH v5 1/5] counter: Internalize sysfs interface code To: William Breathitt Gray , jic23@kernel.org Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com References: From: David Lechner Message-ID: <17c22445-d523-07f8-d1ff-59e8dbc73cc8@lechnology.com> Date: Wed, 14 Oct 2020 20:38:40 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/26/20 9:18 PM, William Breathitt Gray wrote: > +static ssize_t counter_comp_u8_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t len) > +{ > + const struct counter_attribute *const a = to_counter_attribute(attr); > + struct counter_device *const counter = dev_get_drvdata(dev); > + struct counter_count *const count = a->parent; > + struct counter_synapse *const synapse = a->comp.priv; > + const struct counter_available *const avail = a->comp.priv; > + int err; > + bool bool_data; > + u8 data; > + > + switch (a->comp.type) { > + case COUNTER_COMP_BOOL: > + err = kstrtobool(buf, &bool_data); > + data = bool_data; > + break; > + case COUNTER_COMP_FUNCTION: > + err = find_in_string_array(&data, count->functions_list, > + count->num_functions, buf, > + counter_function_str); > + break; > + case COUNTER_COMP_SYNAPSE_ACTION: > + err = find_in_string_array(&data, synapse->actions_list, > + synapse->num_actions, buf, > + counter_synapse_action_str); > + break; > + case COUNTER_COMP_ENUM: > + err = __sysfs_match_string(avail->strs, avail->num_items, buf); > + data = err; > + break; > + case COUNTER_COMP_COUNT_MODE: > + err = find_in_string_array(&data, avail->enums, > + avail->num_items, buf, > + counter_count_mode_str); > + break; > + default: > + err = kstrtou8(buf, 0, &data); > + break; > + } In this function, return values are not always errors. So it would make sense to call the err variable ret instead and check for ret < 0 below. Setting enums to a value with index > 0 fails currently because of this. > + if (err) > + return err; > + > + switch (a->scope) { > + case COUNTER_SCOPE_DEVICE: > + err = a->comp.device_u8_write(counter, data); > + break; > + case COUNTER_SCOPE_SIGNAL: > + err = a->comp.signal_u8_write(counter, a->parent, data); > + break; > + case COUNTER_SCOPE_COUNT: > + if (a->comp.type == COUNTER_COMP_SYNAPSE_ACTION) > + err = a->comp.action_write(counter, count, synapse, > + data); > + else > + err = a->comp.count_u8_write(counter, count, data); > + break; > + } > + if (err) > + return err; > + > + return len; > +}