Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2892645rwb; Mon, 15 Aug 2022 13:27:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR7e9+cnWVWYKt/2z2yJoK1Jx9+vVJshEAjk2MjEzNcGbfsq1z6T43Eq4Wh3PAgkvmGrs8d0 X-Received: by 2002:a17:907:9804:b0:731:8692:f570 with SMTP id ji4-20020a170907980400b007318692f570mr11156912ejc.463.1660595256564; Mon, 15 Aug 2022 13:27:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660595256; cv=none; d=google.com; s=arc-20160816; b=Wr7GBmVXJEif2fQNuyg6404A1d3GufBHnWcZR89ouQwcF8mVlzPPuTaA0pZqVJn3cX K1tfo0JuGgU4pizZX7PeCSvPqi/AN2MVvPaDLtadTgOq1XQR/gvZgB7VgOerjgYErXnr q3HDOe5iwhrCqF5TMB8S+Jnu/wx4pDBdB1baYz/CaOOReB6Edjh+NhSr68QOCEZ1ZzD3 JKiueGQTxvkKTboSJTChtEZPGehXhAB56o/53QLdhvkGcPnk4aNWXPJxh4Lgb2plWcQ0 Nm/SU1Unsks92TrGQb9HRnb2PsI1joSH5ha4EnzA5eRj2EZ6nhYjT563WI7mEW5fLB/M bDdQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vME3ph1yXxeRpDzguSP7t0eIneHU3ScP5tN2naMG6dg=; b=UCjuhAHMl54AS5UBVPwhwyetb8IrVqLgj2ppoW+9SyyjA0ZGE/8FVUXymNJa/7SOBT xH8jr8ouztas4yzk2rg/7P4xXmsM6/Z9o6KMoZP7QmaihhW+JBhiOnculnQ9kOegURdm pclNstm3CDb6oJtCNlA5z+mhzorFDJ3ucAzo02xKyaS7MZ+0VJcDR7/PQPTN4DpNnscz oAKr+fYHQVmS7ZTUuaXOJsdll2SvG0noQJgggADs+HpxdkWH1cozITRtGlO+SANpzdJU Ad7YiL+AUZDbaiB+M16bbxontgxednreuKk02zxGjgs+Y3wJ/6sGEx616zJFUrxCj3MS EeJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ZNhRrlm/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq15-20020a1709073f0f00b0072b44c95da6si9020533ejc.1002.2022.08.15.13.27.08; Mon, 15 Aug 2022 13:27:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ZNhRrlm/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243439AbiHOUTi (ORCPT + 99 others); Mon, 15 Aug 2022 16:19:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347025AbiHOUMr (ORCPT ); Mon, 15 Aug 2022 16:12:47 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BFF289CF9; Mon, 15 Aug 2022 11:58:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id D3496CE129D; Mon, 15 Aug 2022 18:58:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCBB5C433D6; Mon, 15 Aug 2022 18:58:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589926; bh=/Uxe+l8gUs8wUOcFTLTxxqtvEkCdZRTt4cEZRSDrAr0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZNhRrlm/FGMvlu6q1x775FKszWoxF7LcAAdXCnwLdCIuwQQL6LzNhpkP+YIyk0JJk fEwONfJPDZ2Gl7w2VIS5o25gSs41SNBEls7fR0cEbmNirv3FwGlL0Mq/lmejeJdryU s4a1yu3eE3q2ceJiHxeiaMHkd3aRBcSdrdNlTSvE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fawzi Khaber , Jean-Baptiste Maneyrol , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.18 0092/1095] iio: fix iio_format_avail_range() printing for none IIO_VAL_INT Date: Mon, 15 Aug 2022 19:51:31 +0200 Message-Id: <20220815180433.342708066@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fawzi Khaber commit 5e1f91850365de55ca74945866c002fda8f00331 upstream. iio_format_avail_range() should print range as follow [min, step, max], so the function was previously calling iio_format_list() with length = 3, length variable refers to the array size of values not the number of elements. In case of non IIO_VAL_INT values each element has integer part and decimal part. With length = 3 this would cause premature end of loop and result in printing only one element. Signed-off-by: Fawzi Khaber Signed-off-by: Jean-Baptiste Maneyrol Fixes: eda20ba1e25e ("iio: core: Consolidate iio_format_avail_{list,range}()") Link: https://lore.kernel.org/r/20220718130706.32571-1-jmaneyrol@invensense.com Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/industrialio-core.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -821,7 +821,23 @@ static ssize_t iio_format_avail_list(cha static ssize_t iio_format_avail_range(char *buf, const int *vals, int type) { - return iio_format_list(buf, vals, type, 3, "[", "]"); + int length; + + /* + * length refers to the array size , not the number of elements. + * The purpose is to print the range [min , step ,max] so length should + * be 3 in case of int, and 6 for other types. + */ + switch (type) { + case IIO_VAL_INT: + length = 3; + break; + default: + length = 6; + break; + } + + return iio_format_list(buf, vals, type, length, "[", "]"); } static ssize_t iio_read_channel_info_avail(struct device *dev,