Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp100509pxb; Mon, 2 Nov 2020 15:17:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxGmZ7L92tLO+WKSSQzfIt4w21FQpkbJU5jNJnvm+5LgLxHXah1G1Z0zCtxKQjDOp+9Klt X-Received: by 2002:a05:6402:1ad9:: with SMTP id ba25mr19471087edb.120.1604359063748; Mon, 02 Nov 2020 15:17:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604359063; cv=none; d=google.com; s=arc-20160816; b=XQTHMFpdtCDhNvfxbeAKmxl7zy+9zbVOaBYn2BOqjHKvwTBInVgT8X8mbgxOAhnTXR wK0tZ+9dqZePPbQCdYmfzFaNq+VnJOCQCtpsOfUMc1n92lGoWly5z2XbpRRyosoS6l5V RgTL8qK8wWI3QymNH6BJrYvh19ifzJnaO+oDLwmP2UaJHSr5XmKX3m5+20bq2bcxzV0B aMkIJf+RW+xPKGHwd9GF/2ZpM3/g0uzFL/la5Oet/CMr/X6hj55m7MT4TOI/+tVzh3dD 0GF/mDNKuUY+FfChIkrMiR0Wu6Udn/k36Tr/aIVoR5UuUVl1pKGO96EtdrY30DVq0Z6W Qx9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vANG7kCf7McNifCt4i3eNIRIg0UbrbcsPjzgcq/xupY=; b=CCKuf43eoscKoVkfJOlYPwDWQcdVz/1j6M1ukWr3pc1mCOugrnBfKY39l7Y+JcG8OU H8EN2XZ6M8UOxBvQXBOZr2ki+fGEYvhP9gJrfI2bclQWUSrYV3YhjW7D8toTZMHwClyZ 7N92EtkBxUJ2hpHDPnSfQFiZPij+DYWIyGqSqAnw/x2rHs+TJZi9Zo3aY/b1b+PdHyLM cT5pxFGN0g9fpWstYhHGNjl9pItzw0L4/j5ZQ0YpgTdqjHvjCCYNG2WXW87EBj2i3/Wu Da7z0X00fWLLQtjwZ/cCKaoTJVNL+8VJmQ4ThqjadbyhNJVMB7LvZl+iZ73AkVVnJN5h K4Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sartura-hr.20150623.gappssmtp.com header.s=20150623 header.b=h5jLblIV; 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 o6si16990064edi.560.2020.11.02.15.17.21; Mon, 02 Nov 2020 15:17:43 -0800 (PST) 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=pass header.i=@sartura-hr.20150623.gappssmtp.com header.s=20150623 header.b=h5jLblIV; 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 S1726018AbgKBXPv (ORCPT + 99 others); Mon, 2 Nov 2020 18:15:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725831AbgKBXPu (ORCPT ); Mon, 2 Nov 2020 18:15:50 -0500 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E173C0617A6 for ; Mon, 2 Nov 2020 15:15:50 -0800 (PST) Received: by mail-il1-x132.google.com with SMTP id x20so14485195ilj.8 for ; Mon, 02 Nov 2020 15:15:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sartura-hr.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vANG7kCf7McNifCt4i3eNIRIg0UbrbcsPjzgcq/xupY=; b=h5jLblIVHQZxx1Tha8vSPTgmFm12uAoDpNRpw9JwOnw7wxb7HaVuyg/rzFb7Uin+PK zfamwZvGW9EXDR/1Z8lkaWsAd/Dzxp61RRhQEM9IsexjYWO18MheaPDRLsq0qkrJ0vxG RcDDwVRGEGwjG48kWlFIKgZhG399nXw50T63xkcGwa3llVps7XdDhtP7Nh+G0GciaGvo s1HvV7FrH9VimbPIGqpT6ShuZiUX6to6ls1L4Kk6DrO2Jr9K1wnrt54sOxvlDYBiDMw9 /j8kuVpONSCDEHxZ25boboyHsp9J9ViqY/tpiBJm+w9BneEjzgUi5d2VPT6DgDI1wuL/ U9Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vANG7kCf7McNifCt4i3eNIRIg0UbrbcsPjzgcq/xupY=; b=JelY8BolBgNR3Xana9cPzLf8GsLOPZEGh5hFgOPlnilZM6Li5G7UUI9hKVxoPMu2rR oW/spnKCnJjrYs2jp/LIE9NmLO1L2mNvVJyQFBlK6JXq/7EI+q1z8NcEVQMPV7hvBYzl Jp8NvQPkAlLhEsmoD8w8RhpGRFdrIQgvy/xHwdSHG6q1Uf6yObYqqobjnuFhxAnmPMuJ a5IffCRok1gvHWqX8nS0A5JBgF9mS56NtS+oQUR3OS5e6c4qZ6mPB9K+ksLVZJ+EMQRH SR1uKV+zuzxAdkdYPLnd3d0Kd0eTkNTkQ5PvXBOgfDr1WvIA5rtPJvJynBknfgPhIZ1X rWUA== X-Gm-Message-State: AOAM531fFizZpkx6CwjWnPVu5xE9RUQWkV59iTy1qYQIUzhkRi3XZ3B1 9q2B8mjiK1BwT1PLxDwM8NwVPTpskCnbv2WwbSzOBw== X-Received: by 2002:a05:6e02:f12:: with SMTP id x18mr8305779ilj.145.1604358949644; Mon, 02 Nov 2020 15:15:49 -0800 (PST) MIME-Version: 1.0 References: <20201025005916.64747-1-luka.kovacic@sartura.hr> <20201025005916.64747-3-luka.kovacic@sartura.hr> In-Reply-To: From: Luka Kovacic Date: Tue, 3 Nov 2020 00:15:38 +0100 Message-ID: Subject: Re: [PATCH v7 2/6] drivers: mfd: Add a driver for IEI WT61P803 PUZZLE MCU To: Andy Shevchenko Cc: Linux Kernel Mailing List , linux-hwmon@vger.kernel.org, Linux LED Subsystem , devicetree , Lee Jones , Pavel Machek , Dan Murphy , Rob Herring , Jean Delvare , Guenter Roeck , =?UTF-8?B?TWFyZWsgQmVow7pu?= , Luka Perkov , Robert Marko Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Andy, On Mon, Nov 2, 2020 at 12:18 PM Andy Shevchenko wrote: > > On Sun, Nov 1, 2020 at 3:22 PM Luka Kovacic wrote: > > On Mon, Oct 26, 2020 at 11:54 PM Andy Shevchenko > > wrote: > > > On Sun, Oct 25, 2020 at 3:59 AM Luka Kovacic wrote: > > ... > > > > > +#include > > > > > > Don't see a user of this, but of_platform.h seems to be missed. > > > > Okay, I'll add it. > > I'm still using devm_of_platform_populate() in iei_wt61p803_puzzle_probe(). > > Yes, and that's why I have mentioned of_platform.h above. > > ... > > > > > + struct kobject *kobj; > > > > > > It's quite strange you need this, > > > > This is used in iei_wt61p803_puzzle_sysfs_create() and > > iei_wt61p803_puzzle_sysfs_remove() to clean up afterwards. > > I didn't get why you need this in the first place. > > ... > > > > > + /* Return the number of processed bytes if function returns error */ > > > > + if (ret < 0) > > > > > > > + return (int)size; > > > > > > Will be interesting result, maybe you wanted other way around? > > > > That is intentional. > > A single frame is concatenated in the iei_wt61p803_puzzle_process_resp() > > function. In case we find ourselves in an unknown state, an error is > > returned there. > > > > We want to discard the remaining incoming data, since the frame this > > data belongs > > to is broken anyway. > > Elaborate in the comment. Okay. > > > > > + return ret; > > ... > > > > > +err: > > > > > > err_unlock: ? > > > > I use goto only in case there is also a mutex to unlock, so I don't see why > > to change this. > > The comment was about clarification of what is done at this label. Ok, I understand. I will change the labels where mutexes are unlocked to indicate this as you suggested. > > > > > + mutex_unlock(&mcu->lock); > > > > + return ret; > > ... > > > > > + /* Response format: > > > > + * (IDX RESPONSE) > > > > + * 0 @ > > > > + * 1 O > > > > + * 2 S > > > > + * 3 S > > > > + * ... > > > > + * 5 AC Recovery Status Flag > > > > + * ... > > > > + * 10 Power Loss Recovery > > > > + * ... > > > > + * 19 Power Status (system power on method) > > > > + * 20 XOR checksum > > > > + */ > > > > > > Shouldn't be rather defined data structure for response? > > > > Every response, apart from the standard headers and a checksum > > at the end is completely different and I don't see a good way to > > standardize that in some other way. > > And that's my point. Provide data structures for all responses you are > taking care of. > It will be way better documentation and understanding of this IPC. Okay, I'll improve handling of these in the next patchset. Should I make a generic header structure for the common parts and define the common responses somewhere centrally? Then I can check those just as you suggested. For the variable ones I can reuse the generic header structure and just use the specific values as I would do normally. > > ... > > > > > + if (!(resp_buf[0] == IEI_WT61P803_PUZZLE_CMD_HEADER_START && > > > > + resp_buf[1] == IEI_WT61P803_PUZZLE_CMD_RESPONSE_OK && > > > > + resp_buf[2] == IEI_WT61P803_PUZZLE_CHECKSUM_RESPONSE_OK)) { > > > > + ret = -EPROTO; > > > > + goto err; > > > > + } > > > > > > I think it would be better to define data structure for replies and > > > then check would be as simple as memcmp(). > > > > I'd keep this as is, because the replies are different a lot of the times. > > Especially when the reply isn't just an ACK. > > How do you know the type of the reply? Can't you provide a data > structure which will have necessary fields to recognize this? > It can be recognized by the specific header of the reply. I will separate the header and the checksum into some kind of a generic structure, but as the content itself is just an arbitrary array of characters I cannot generalize that sensibly for every type of a reply there is. Anyway, I agree it would be good to define the common responses... > ... > > > > > + power_loss_recovery_cmd[3] = cmd_buf[0]; > > > > > > One decimal (most significant) digit?! Isn't it a bit ambiguous? > > > > The power_loss_recovery_action can only have a value of 0 - 4. > > My understanding is that if I give snprintf a buffer of size 1, it will > > truncate the one character to make space for NUL. > > Why to bother with snprintf()? hex_asc[] would be sufficient. But my > point that the code is fragile. If it ever gets 15, you will get 1. Ok, I'll simplify this. > > ... > > > I can reduce this, but I'd just like to log the baud rate and the > > firmware build info. > > > These two could be useful in a kernel log, if something doesn't work. > > FW build info is definitely good to have, but don't you have other > means to retrieve baud rate? The normal boot log is completely clean, there are no serdev bus specific messages. The baud rate is defined in the device tree, so if something goes wrong it should be sufficient to only print the baud rate then. Can I output the versions, the firmware build info and only print the baud rate when an error occurs? > > -- > With Best Regards, > Andy Shevchenko