Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1044776AbdDWKLT (ORCPT ); Sun, 23 Apr 2017 06:11:19 -0400 Received: from m50-132.163.com ([123.125.50.132]:34585 "EHLO m50-132.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1044518AbdDWKLL (ORCPT ); Sun, 23 Apr 2017 06:11:11 -0400 From: Pan Bian To: Eli Billauer Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] char: xillybus: check return value Date: Sun, 23 Apr 2017 18:10:49 +0800 Message-Id: <1492942249-25142-1-git-send-email-bianpan201602@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DNGowAAn2xWpffxYsSMeAA--.638S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7XrW5Xr4rXw17KF45Cr45Jrb_yoWDArb_Ca 18Zr4xWrs5Kr1DGw1UKay7ur4fAF13X3Z8GF1Dta43Ar1fArsrury8Wr1kZwn5GrsavryD C347Zr15uF45KjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8DGYJUUUUU== X-Originating-IP: [123.118.194.153] X-CM-SenderInfo: held01tdqsiiqwqsqiywtou0bp/1tbiuAzC4FQG8nVXvgAAsq Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 966 Lines: 29 From: Pan Bian Function of_address_to_resource() tries to translate device tree address and return as resource. If the translation fails, it will return a negative errno. However, function xilly_drv_probe() does not validate its return value, which may result in a bad memory access bug. This patch fixes the bug. Signed-off-by: Pan Bian --- drivers/char/xillybus/xillybus_of.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/char/xillybus/xillybus_of.c b/drivers/char/xillybus/xillybus_of.c index 78a492f..57b295a 100644 --- a/drivers/char/xillybus/xillybus_of.c +++ b/drivers/char/xillybus/xillybus_of.c @@ -137,6 +137,8 @@ static int xilly_drv_probe(struct platform_device *op) dev_set_drvdata(dev, endpoint); rc = of_address_to_resource(dev->of_node, 0, &res); + if (rc < 0) + return rc; endpoint->registers = devm_ioremap_resource(dev, &res); if (IS_ERR(endpoint->registers)) -- 1.9.1