Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E861DC433F5 for ; Tue, 16 Nov 2021 02:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CBDB960EFE for ; Tue, 16 Nov 2021 02:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243389AbhKPCaE (ORCPT ); Mon, 15 Nov 2021 21:30:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:46816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237033AbhKORQM (ORCPT ); Mon, 15 Nov 2021 12:16:12 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2470E63263; Mon, 15 Nov 2021 17:12:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1636996349; bh=mgTj62vd/B9dx4Plg0wOv90Sqq+ryL27UCC5jKoo1Z4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gpFG9T3UjSdVpSt4oLI84IYo02R+WdLGDsEZBqDKPm/jywwZegQTgjYcdH7OYxlr0 Isf1VMKxGQpekYpVD2r1mfBiqVX4/DKnDk6WpJDLLb6/BJYTYxYSnlNztRSlWyYVMD 49WqU85o8g8mNDY87PtT03mr8efFsMVS1ZXIeJOs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pekka Korpinen , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.4 108/355] iio: dac: ad5446: Fix ad5622_write() return value Date: Mon, 15 Nov 2021 18:00:32 +0100 Message-Id: <20211115165317.301582571@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211115165313.549179499@linuxfoundation.org> References: <20211115165313.549179499@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pekka Korpinen commit 558df982d4ead9cac628153d0d7b60feae05ddc8 upstream. On success i2c_master_send() returns the number of bytes written. The call from iio_write_channel_info(), however, expects the return value to be zero on success. This bug causes incorrect consumption of the sysfs buffer in iio_write_channel_info(). When writing more than two characters to out_voltage0_raw, the ad5446 write handler is called multiple times causing unexpected behavior. Fixes: 3ec36a2cf0d5 ("iio:ad5446: Add support for I2C based DACs") Signed-off-by: Pekka Korpinen Link: https://lore.kernel.org/r/20210929185755.2384-1-pekka.korpinen@iki.fi Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/dac/ad5446.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/iio/dac/ad5446.c +++ b/drivers/iio/dac/ad5446.c @@ -527,8 +527,15 @@ static int ad5622_write(struct ad5446_st { struct i2c_client *client = to_i2c_client(st->dev); __be16 data = cpu_to_be16(val); + int ret; - return i2c_master_send(client, (char *)&data, sizeof(data)); + ret = i2c_master_send(client, (char *)&data, sizeof(data)); + if (ret < 0) + return ret; + if (ret != sizeof(data)) + return -EIO; + + return 0; } /**