From patchwork Fri Jan 24 09:31:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 232908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E9A2C2D0DB for ; Fri, 24 Jan 2020 11:30:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 127FF20838 for ; Fri, 24 Jan 2020 11:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865434; bh=4yGlxUDqWwi547uB96hssKWc2DcDoNH01Ll02HHWk0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=pGIau3sQNMHK5EIEcCdhSJxZQp6LWBO9+y7OwHZJyYnWBdQM57o7MQjS4Zc0tHOt9 poWN6yII8ehTMq996RIC5EO84H8yzaqZVp1WAHGxENm0LTkZIn1KLk96ZKZP5zW0E2 EVDUat3KFxPFymtLvrxn5xN3RdtcgTTMJM10nzTo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404220AbgAXLaV (ORCPT ); Fri, 24 Jan 2020 06:30:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:47988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404214AbgAXLaU (ORCPT ); Fri, 24 Jan 2020 06:30:20 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (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 31F2E2075D; Fri, 24 Jan 2020 11:30:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865420; bh=4yGlxUDqWwi547uB96hssKWc2DcDoNH01Ll02HHWk0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c07XfzZMq5iDpWiFYvSfFTzUA8oTd+f31IrTkfxtDCI5QBJKfDlJ22IjHjy9g69Ra dnv55OMcYFCXLZRT3xmqs7kQ+JGML86Jq1oUBLrCvpu2mSUDq0roh3cBw4UpAdDe+6 gb9FLCLKFKfUbq49ej1l57n1bQe/xkTRsDv6xjmM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Iker Perez del Palomar Sustatxa , Guenter Roeck , Sasha Levin Subject: [PATCH 4.19 528/639] hwmon: (lm75) Fix write operations for negative temperatures Date: Fri, 24 Jan 2020 10:31:38 +0100 Message-Id: <20200124093154.955059880@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Guenter Roeck [ Upstream commit 7d82fcc9d9e81241778aaa22fda7be753e237d86 ] Writes into limit registers fail if the temperature written is negative. The regmap write operation checks the value range, regmap_write accepts an unsigned int as parameter, and the temperature value passed to regmap_write is kept in a variable declared as long. Negative values are converted large unsigned integers, which fails the range check. Fix by type casting the temperature to u16 when calling regmap_write(). Cc: Iker Perez del Palomar Sustatxa Fixes: e65365fed87f ("hwmon: (lm75) Convert to use regmap") Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/lm75.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 49f4b33a5685a..7f28912c9abcf 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -165,7 +165,7 @@ static int lm75_write(struct device *dev, enum hwmon_sensor_types type, temp = DIV_ROUND_CLOSEST(temp << (resolution - 8), 1000) << (16 - resolution); - return regmap_write(data->regmap, reg, temp); + return regmap_write(data->regmap, reg, (u16)temp); } static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type,