From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941822AbcJYTEX (ORCPT ); Tue, 25 Oct 2016 15:04:23 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:42905 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932538AbcJYTEV (ORCPT ); Tue, 25 Oct 2016 15:04:21 -0400 From: Colin King To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , sayli karnik , Matt Ranostay , Wei Yongjun , linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] iio: maxim_thermocouple: return -EINVAL on invalid read size Date: Tue, 25 Oct 2016 20:04:08 +0100 Message-Id: <20161025190408.5012-1-colin.king@canonical.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King In the case that the read size is not 2 or 4 bytes then maxim_thermocouple_read is not initializing ret and hence may return early with a bogus error return or just through to return with a bogos unread value in *val. Fix this by setting ret to -EINVAL for invalid (unhandled) read sizes. Signed-off-by: Colin Ian King --- drivers/iio/temperature/maxim_thermocouple.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c index 066161a..f962f31 100644 --- a/drivers/iio/temperature/maxim_thermocouple.c +++ b/drivers/iio/temperature/maxim_thermocouple.c @@ -136,6 +136,8 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data, ret = spi_read(data->spi, (void *)&buf32, storage_bytes); *val = be32_to_cpu(buf32); break; + default: + ret = -EINVAL; } if (ret) -- 2.9.3