Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1021095pxb; Sun, 21 Feb 2021 08:33:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxlqER4WFb3TE/PXmmuHEYeTasXBK+JWfPhnwfrIMGWQlqvxCOvlHGl5ebDj/cK2jne/m5w X-Received: by 2002:a05:6402:5243:: with SMTP id t3mr18606698edd.361.1613925209021; Sun, 21 Feb 2021 08:33:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613925209; cv=none; d=google.com; s=arc-20160816; b=ciCZT7qqUZDG9TtUI0eVITdugy3qJdmLeiyC46hvRTuI0w7DcvyrMdeBpXEGBQpeTJ N9rVgpixJMZsTOSBr+DFc0lcXMRkIPkTfHtxCJMny66pW+431Vy6fIBnTfYHw8MAntP+ sJCq+ksbYBupLXv7ncBqsKl9nWqS/ep2syk7f5iL9fAccmbzkRddBnjtfJsObBupaF/F 7LZlR84LPZhgO9f5o8Wo/iLv1d8xbgcyw8FkJSnH2u53wUllBd9F/p5tghbGzVIdzI13 bevxatxbkNw9PgHa1lfLdFZcPt+6E7cPw5lhan6ZVMuQScDwirEg7doWDzr3l8CL+b+b CTRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=gdULKsZgtTYARS2R5bb6wSc7jQMbeyNSmXKxdORDl98=; b=Y5DcqHmqZPc7WG9cfKeYY/hFFzk+9e0b0VJ5+fFlrG2CO3GLajCXVEm2NUZMor/vZ/ 6MA7bApv/WMnc1orQc8E0F2raJEYWGBTHXQtnnRC24mrt4eKLt3sXB72tosDX3wvURuY jKir3Qs0V8p/a3QayPZP+mAeNpcLRFugKh/9wzn2db4xbq1gYiKF0mk5tVr5UpgdKoZD U8SfGI+Q9C+VU892DSaQjE3PGyR2+D+A8tKSk07OAo3jneBKg0IZ5RH2i1Ny+Se5OoXr YKkjC0Ud+ukufiJlh9xa7YPpuQBwrOP+RkfPHOC2rMNss0J6QERr1l3mANORn/rfU1EI HBYQ== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c9si10198028edq.47.2021.02.21.08.33.05; Sun, 21 Feb 2021 08:33:29 -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; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbhBUQ3x (ORCPT + 99 others); Sun, 21 Feb 2021 11:29:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:54612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbhBUQ3w (ORCPT ); Sun, 21 Feb 2021 11:29:52 -0500 Received: from archlinux (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 20EAE600CC; Sun, 21 Feb 2021 16:29:08 +0000 (UTC) Date: Sun, 21 Feb 2021 16:29:05 +0000 From: Jonathan Cameron To: Alexandru Ardelean Cc: , , , , , Subject: Re: [PATCH 1/2] iio: cros_ec: do an early exit if not physical_device case Message-ID: <20210221162905.65be88d0@archlinux> In-Reply-To: <20201123144017.18311-1-alexandru.ardelean@analog.com> References: <20201123144017.18311-1-alexandru.ardelean@analog.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 23 Nov 2020 16:40:16 +0200 Alexandru Ardelean wrote: > This whole code-block was put under one big if() condition/block. > This change does an early return if the 'physical_device' boolean is false, > thus unindenting the block by one level. > > No other functional change has been done. > > Signed-off-by: Alexandru Ardelean @Gwendal, others This series from Alex has been outstanding for a while but may well still apply. Ideally looking for an ack. Thanks, Jonathan > --- > .../cros_ec_sensors/cros_ec_sensors_core.c | 161 +++++++++--------- > 1 file changed, 81 insertions(+), 80 deletions(-) > > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c > index 5c6c4e6fec9b..9470014936f2 100644 > --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c > @@ -287,89 +287,90 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, > > indio_dev->name = pdev->name; > > - if (physical_device) { > - state->param.cmd = MOTIONSENSE_CMD_INFO; > - state->param.info.sensor_num = sensor_platform->sensor_num; > - ret = cros_ec_motion_send_host_cmd(state, 0); > - if (ret) { > - dev_warn(dev, "Can not access sensor info\n"); > + if (!physical_device) > + return 0; > + > + state->param.cmd = MOTIONSENSE_CMD_INFO; > + state->param.info.sensor_num = sensor_platform->sensor_num; > + ret = cros_ec_motion_send_host_cmd(state, 0); > + if (ret) { > + dev_warn(dev, "Can not access sensor info\n"); > + return ret; > + } > + state->type = state->resp->info.type; > + state->loc = state->resp->info.location; > + > + /* Set sign vector, only used for backward compatibility. */ > + memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS); > + > + for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++) > + state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE; > + > + /* 0 is a correct value used to stop the device */ > + if (state->msg->version < 3) { > + get_default_min_max_freq(state->resp->info.type, > + &frequencies[1], > + &frequencies[2], > + &state->fifo_max_event_count); > + } else { > + frequencies[1] = state->resp->info_3.min_frequency; > + frequencies[2] = state->resp->info_3.max_frequency; > + state->fifo_max_event_count = > + state->resp->info_3.fifo_max_event_count; > + } > + for (i = 0; i < ARRAY_SIZE(frequencies); i++) { > + state->frequencies[2 * i] = frequencies[i] / 1000; > + state->frequencies[2 * i + 1] = > + (frequencies[i] % 1000) * 1000; > + } > + > + if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) { > + /* > + * Create a software buffer, feed by the EC FIFO. > + * We can not use trigger here, as events are generated > + * as soon as sample_frequency is set. > + */ > + struct iio_buffer *buffer; > + > + buffer = devm_iio_kfifo_allocate(dev); > + if (!buffer) > + return -ENOMEM; > + > + iio_device_attach_buffer(indio_dev, buffer); > + indio_dev->modes = INDIO_BUFFER_SOFTWARE; > + > + ret = cros_ec_sensorhub_register_push_data( > + sensor_hub, sensor_platform->sensor_num, > + indio_dev, push_data); > + if (ret) > return ret; > - } > - state->type = state->resp->info.type; > - state->loc = state->resp->info.location; > > - /* Set sign vector, only used for backward compatibility. */ > - memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS); > + ret = devm_add_action_or_reset( > + dev, cros_ec_sensors_core_clean, pdev); > + if (ret) > + return ret; > > - for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++) > - state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE; > - > - /* 0 is a correct value used to stop the device */ > - if (state->msg->version < 3) { > - get_default_min_max_freq(state->resp->info.type, > - &frequencies[1], > - &frequencies[2], > - &state->fifo_max_event_count); > - } else { > - frequencies[1] = state->resp->info_3.min_frequency; > - frequencies[2] = state->resp->info_3.max_frequency; > - state->fifo_max_event_count = > - state->resp->info_3.fifo_max_event_count; > - } > - for (i = 0; i < ARRAY_SIZE(frequencies); i++) { > - state->frequencies[2 * i] = frequencies[i] / 1000; > - state->frequencies[2 * i + 1] = > - (frequencies[i] % 1000) * 1000; > - } > - > - if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) { > - /* > - * Create a software buffer, feed by the EC FIFO. > - * We can not use trigger here, as events are generated > - * as soon as sample_frequency is set. > - */ > - struct iio_buffer *buffer; > - > - buffer = devm_iio_kfifo_allocate(dev); > - if (!buffer) > - return -ENOMEM; > - > - iio_device_attach_buffer(indio_dev, buffer); > - indio_dev->modes = INDIO_BUFFER_SOFTWARE; > - > - ret = cros_ec_sensorhub_register_push_data( > - sensor_hub, sensor_platform->sensor_num, > - indio_dev, push_data); > - if (ret) > - return ret; > - > - ret = devm_add_action_or_reset( > - dev, cros_ec_sensors_core_clean, pdev); > - if (ret) > - return ret; > - > - /* Timestamp coming from FIFO are in ns since boot. */ > - ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME); > - if (ret) > - return ret; > - } else { > - const struct attribute **fifo_attrs; > - > - if (has_hw_fifo) > - fifo_attrs = cros_ec_sensor_fifo_attributes; > - else > - fifo_attrs = NULL; > - > - /* > - * The only way to get samples in buffer is to set a > - * software trigger (systrig, hrtimer). > - */ > - ret = devm_iio_triggered_buffer_setup_ext( > - dev, indio_dev, NULL, trigger_capture, > - NULL, fifo_attrs); > - if (ret) > - return ret; > - } > + /* Timestamp coming from FIFO are in ns since boot. */ > + ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME); > + if (ret) > + return ret; > + } else { > + const struct attribute **fifo_attrs; > + > + if (has_hw_fifo) > + fifo_attrs = cros_ec_sensor_fifo_attributes; > + else > + fifo_attrs = NULL; > + > + /* > + * The only way to get samples in buffer is to set a > + * software trigger (systrig, hrtimer). > + */ > + ret = devm_iio_triggered_buffer_setup_ext( > + dev, indio_dev, NULL, trigger_capture, > + NULL, fifo_attrs); > + if (ret) > + return ret; > } > > return 0;