Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2564273pxk; Sun, 6 Sep 2020 05:12:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvgZSI2H3LMunh1zVWXYdLTy7+Tsb0/cpj/dFv2+aBUHl22faGRn8ILiHHeIPUEQI3Jzw5 X-Received: by 2002:aa7:c504:: with SMTP id o4mr17601859edq.82.1599394330050; Sun, 06 Sep 2020 05:12:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599394330; cv=none; d=google.com; s=arc-20160816; b=euoo1ZWcknMHIOL8mvjwE8+O/21xm+mMlMra/rj/SWqpnpWBGMlCXfZNeoaqkiId/m 3RqsGOHdznuzIIHLOxNRrlF1wLEoLpsRM0+EYn4Vl0uXX1/3Cytwz4obvm3eP6JDmI7S cyCxQRt+RuBKaRY6Y/d49CD25+thwZ/JTtVHOSHHOPi0PVkoHDsOFkJwYb/ywinoH8Z/ P5gKoX8y94AlBBwFoirkKJjg2PcVpSdL/fpKZj6m8dgcMwKUDgr3GoQZmryMA28LC61P nJRAHsA+Lrj/tLcxdO6073wSt9LSrYEO8HlpeEi1PQVsd/4wUru5xoLLtGmpOivlbngQ krRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version; bh=sp3LAal/SVUFeq6svxTCnm0Bbx3V/AMVSJBGN+D2DB4=; b=wpODF6I6ghJOEz6cvAKRQtsWzQxHPopidp4mf1MPe/EAYTBoJqiWL9RTVTGlJI65Wy +lFG7QsqRVyIw1s7KkL2aRJ41dC/0TRohU05KJ+MHTDw8pVdBpBRsIXFTOH6ajQVb/nz tKB0VCCtEASZH5MXu7/HBuh42QAmVC5oWNWLTysMy0QZo4j4BroTeWMxu2Y5fEKvFtia EzFvR894RQTVF+4GLKK7LQYF/oYd+zoTlxpycpiJ7SPiXN4vwiIJKU2NRNqSNp/fJUmO Zzvcx5arIHuuTVAQbNJdOpC4Pz6/p6M4mO5ODNmVmc0OL3TP1FYuBVne2bNK8WTHlYIn ziTA== ARC-Authentication-Results: i=1; mx.google.com; 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 y102si8352828ede.258.2020.09.06.05.11.37; Sun, 06 Sep 2020 05:12:10 -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; 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 S1728681AbgIFMJt (ORCPT + 99 others); Sun, 6 Sep 2020 08:09:49 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:50543 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbgIFMJf (ORCPT ); Sun, 6 Sep 2020 08:09:35 -0400 Received: from webmail.gandi.net (webmail15.sd4.0x35.net [10.200.201.15]) (Authenticated sender: contact@artur-rojek.eu) by relay8-d.mail.gandi.net (Postfix) with ESMTPA id EFD411BF203; Sun, 6 Sep 2020 12:09:28 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 06 Sep 2020 14:09:28 +0200 From: Artur Rojek To: Andy Shevchenko Cc: Dmitry Torokhov , Rob Herring , Mark Rutland , Jonathan Cameron , Paul Cercueil , Heiko Stuebner , Ezequiel Garcia , linux-input , devicetree , Linux Kernel Mailing List Subject: Re: [PATCH v9 2/2] input: joystick: Add ADC attached joystick driver. In-Reply-To: References: <20200905163403.64390-1-contact@artur-rojek.eu> <20200905163403.64390-2-contact@artur-rojek.eu> Message-ID: <2f2047e7ada6fcb70489ea6e5917e20a@artur-rojek.eu> X-Sender: contact@artur-rojek.eu User-Agent: Roundcube Webmail/1.3.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, thanks for the review, replies inline. On 2020-09-06 11:22, Andy Shevchenko wrote: > On Sat, Sep 5, 2020 at 7:34 PM Artur Rojek > wrote: >> >> Add a driver for joystick devices connected to ADC controllers >> supporting the Industrial I/O subsystem. > > ... > >> +static int adc_joystick_handle(const void *data, void *private) >> +{ >> + struct adc_joystick *joy = private; >> + enum iio_endian endianness; >> + int bytes, msb, val, idx, i; >> + bool sign; >> + >> + bytes = joy->chans[0].channel->scan_type.storagebits >> 3; >> + >> + for (i = 0; i < joy->num_chans; ++i) { >> + idx = joy->chans[i].channel->scan_index; >> + endianness = >> joy->chans[i].channel->scan_type.endianness; >> + msb = joy->chans[i].channel->scan_type.realbits - 1; > >> + sign = (tolower(joy->chans[i].channel->scan_type.sign) >> == 's'); > > Redundant parentheses. > >> + switch (bytes) { >> + case 1: >> + val = ((const u8 *)data)[idx]; >> + break; >> + case 2: > >> + if (endianness == IIO_BE) >> + val = be16_to_cpu(((const __be16 >> *)data)[idx]); >> + else if (endianness == IIO_LE) >> + val = le16_to_cpu(((const __le16 >> *)data)[idx]); >> + else /* IIO_CPU */ >> + val = ((const u16 *)data)[idx]; >> + break; > > Hmm... I don't like explicit castings to restricted types. On top of > that is it guaranteed that pointer to data will be aligned? The buffer comes from the IIO core, it is aligned to the sample size. > As a solution for the first two I would recommend to use > get_unaligned_be16() / get_unaligned_le16(). > The last one is an interesting case and if data can be unaligned needs > to be fixed. > >> + default: >> + return -EINVAL; >> + } >> + >> + val >>= joy->chans[i].channel->scan_type.shift; >> + if (sign) >> + val = sign_extend32(val, msb); >> + else > >> + val &= GENMASK(msb, 0); > > It includes msb. Is it expected? Yes, that's expected as `msb = joy->chans[i].channel->scan_type.realbits - 1`. > >> + input_report_abs(joy->input, joy->axes[i].code, val); >> + } >> + >> + input_sync(joy->input); >> + >> + return 0; >> +} > > ... > >> +static int adc_joystick_open(struct input_dev *dev) > >> +static void adc_joystick_close(struct input_dev *dev) > > Just wondering if this is protected against object lifetime cases. Can you clarify that in more details? > > ... > >> +err: > > err_fwnode_put: ? > >> + fwnode_handle_put(child); >> + return ret; > > ... > >> + /* Count how many channels we got. NULL terminated. */ >> + for (i = 0; joy->chans[i].indio_dev; ++i) { >> + bits = joy->chans[i].channel->scan_type.storagebits; >> + if (!bits || (bits > 16)) { >> + dev_err(dev, "Unsupported channel storage >> size\n"); > >> + return -EINVAL; > > -ERANGE? > >> + } >> + if (bits != >> joy->chans[0].channel->scan_type.storagebits) { >> + dev_err(dev, "Channels must have equal storage >> size\n"); >> + return -EINVAL; >> + } >> + }