Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp105667imm; Thu, 2 Aug 2018 14:56:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfrxd2cmrO4zar94P6qokjf2VepPEh/J37KJSQAhz0m0U79pQdlN6EDugqEZdf8sGW3psym X-Received: by 2002:a17:902:1c8:: with SMTP id b66-v6mr1017299plb.273.1533246981098; Thu, 02 Aug 2018 14:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533246981; cv=none; d=google.com; s=arc-20160816; b=kIiGNaKWDMdBddrRHz6OEKQgrAQxvTpF36OxXFPPYLbtb6+Hiz6pVybqntxYHn58vk ZjE4smbqtIz1lmaqmR+QzDdAY3BdtKsKH/EKEbZXrUaYozkGXSaCVHH0W01BkpbAZuQC 7WakBYinfd8TRSLOPQUDOPgsc5FLXZ6yKT9BbnSCjcsuXBMUcGFsICcHIDWXL91T2Jax lX37lBTE2htCSQ5aQ0fauVRw02INQJZWVapgoplUKaRGGsmf/WfL9wF/5GtFRA/zdzio ZG6yUmHhGaHVLBTOOO8VRgR7xDpGNwyApusq2PsCqb+IHwwKCccRVRA3rp1FkPgu8x6d s0XQ== 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=hDo64eeItt5T9UxE2nsFi+Bp1dQ740xkVGLMqbOAVbo=; b=tI3vbubFikfW0zY0uRuYjyZ8fT4ulcdHyIFL3DpGLOFKtFXCjHViNuLx28AyzGCZPI D7ZumrM3lh8I2oHjATaV+NMvBGtRIENomwlxBAP20Mis/dLUCF+puiKXdEQuq0w9x1my MHDvTFENbfnXrQGdiO1YQa7kUdbgbQWRqTrKbStn0WOmbi80W0sN60EGOUUAJL3i74k1 EK8ywoHAAOnjXuXBbazeO8CuP7pRA2Cij8KRiCbgEn25D2ifd8vmfW1uAm8fzAYImsbx YnvJwj4ZA/+rvmt8SZ7EeZaTjDlQK9qcttVsDV8haEQnaC46VKkzXaO86B55uW3ERLo5 ufiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N3bNNaec; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h18-v6si2906265pgd.238.2018.08.02.14.56.06; Thu, 02 Aug 2018 14:56:21 -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=@linaro.org header.s=google header.b=N3bNNaec; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732368AbeHBXsX (ORCPT + 99 others); Thu, 2 Aug 2018 19:48:23 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38972 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732006AbeHBXsX (ORCPT ); Thu, 2 Aug 2018 19:48:23 -0400 Received: by mail-pf1-f196.google.com with SMTP id j8-v6so2072713pff.6 for ; Thu, 02 Aug 2018 14:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=hDo64eeItt5T9UxE2nsFi+Bp1dQ740xkVGLMqbOAVbo=; b=N3bNNaecAvR+vDqNR/CH/DTW7iDT7M3ZsAXVDGWXSewAEdLDTeJmX7X0LzsQOmlcoT CX3Z+uuIysJ5QU4naVreQ3+8pLl4MSUSXvmTbGLF+JpgqvpG2lHUL66xijGeSpU5A/Du 85dPGV2hS/+EUrLALxXv28o4MPF8kZKlCQ4UA= 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=hDo64eeItt5T9UxE2nsFi+Bp1dQ740xkVGLMqbOAVbo=; b=B81Etd49y5Am/ALWCX9WquZZd7t3PMQbpdiUBA6zlQvuzWVHJA2sALeefocpqwjWsq bBV/IBbowiFzxsEvPeNqXeVph6Rjkpoo1DJ24E9XOVe0qIzU8TNeCfLntmqMPcXHCxqc VQvSRSZhnyDHcguzlu2NIb0XwmKjubv6njJ8wcmM5urujAso+pFVfzLhSn8fsU9Y/LaZ pl16jwx9j1V2g496JVr+a9ki7ayv41oNtXoupmbGA/0aQSF6OTGZ7zHiaOn8CBivfB5S YSu6So+nF/2wg5PzSYk3dGA3WgSUisA2x8OYB1t0ONW0iMicsBgR9VRGusoldYYpVtn+ r57g== X-Gm-Message-State: AOUpUlErDr5er8sO+0HouPjO1gebdLGFwZKWXKHpuUZxRhW2lB1br6Xg J9PXpn/QifcLyTRkYjk3m+22fresjzY= X-Received: by 2002:a62:3545:: with SMTP id c66-v6mr1283947pfa.63.1533246919476; Thu, 02 Aug 2018 14:55:19 -0700 (PDT) Received: from minitux (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id d26-v6sm6684387pfl.159.2018.08.02.14.55.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Aug 2018 14:55:18 -0700 (PDT) Date: Thu, 2 Aug 2018 14:53:40 -0700 From: Bjorn Andersson To: Jacek Anaszewski Cc: Baolin Wang , pavel@ucw.cz, rteysseyre@gmail.com, david@lechnology.com, broonie@kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] leds: core: Introduce LED pattern trigger Message-ID: <20180802215340.GP30024@minitux> References: <1bf9aed83d1756dd4f81590297ce7e0b9972bf85.1533112637.git.baolin.wang@linaro.org> <34c87589-ccaf-e541-7acb-efcf3bd306f6@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <34c87589-ccaf-e541-7acb-efcf3bd306f6@gmail.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 02 Aug 14:21 PDT 2018, Jacek Anaszewski wrote: > On 08/01/2018 11:01 AM, Baolin Wang wrote: [..] > > diff --git a/drivers/leds/trigger/ledtrig-pattern.c b/drivers/leds/trigger/ledtrig-pattern.c [..] > > +static ssize_t pattern_trig_store_pattern(struct device *dev, > > + struct device_attribute *attr, > > + const char *buf, size_t count) > > +{ > > + struct led_classdev *led_cdev = dev_get_drvdata(dev); > > + struct pattern_trig_data *data = led_cdev->trigger_data; > > + int cr, ccount, offset = 0, err = 0; > > + > > + if (!data->hardware_pattern) > > + del_timer_sync(&data->timer); > > + > > + mutex_lock(&data->lock); > > + > > + data->npatterns = 0; > > + while (offset < count - 1 && data->npatterns < MAX_PATTERNS) { > > + cr = 0; > > + ccount = sscanf(buf + offset, "%d %d " PATTERN_SEPARATOR "%n", > > + &data->patterns[data->npatterns].brightness, > > + &data->patterns[data->npatterns].delta_t, &cr); > > In case user makes a typo while constructing list of pattern tuples, > e.g. he forgets a comma, the pattern gets silently truncated. > > User is able to detect the truncation by reading pattern file, > but it is not an immediate feedback anyway. > I agree, a failure to parse the entire pattern should result in an error returned, rather than just silently truncating the pattern. > I propose that pattern format should require number of tuples in the > first position which would allow to get rid of this ambiguity, since > we could verify if the number of parsed tuples is as intended. > I would prefer to see that we check that we have consumed the entire input (accepting optional \n end), rather than having to prepend a count to the string... Regards, Bjorn