From patchwork Tue Oct 4 09:09:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 9361395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7B9EF608A6 for ; Tue, 4 Oct 2016 09:10:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6821428980 for ; Tue, 4 Oct 2016 09:10:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CDDF28799; Tue, 4 Oct 2016 09:10:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A0C628799 for ; Tue, 4 Oct 2016 09:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752296AbcJDJJj (ORCPT ); Tue, 4 Oct 2016 05:09:39 -0400 Received: from xavier.telenet-ops.be ([195.130.132.52]:33532 "EHLO xavier.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751648AbcJDJJi (ORCPT ); Tue, 4 Oct 2016 05:09:38 -0400 Received: from ayla.of.borg ([84.193.137.253]) by xavier.telenet-ops.be with bizsmtp id rM9b1t0015UCtCs01M9bHZ; Tue, 04 Oct 2016 11:09:37 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1brLjD-0003wz-0c; Tue, 04 Oct 2016 11:09:35 +0200 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1brLjD-0007i1-PR; Tue, 04 Oct 2016 11:09:35 +0200 From: Geert Uytterhoeven To: Simon Horman , Magnus Damm , Greg Kroah-Hartman , Arnd Bergmann , Yangbo Lu Cc: Lee Jones , Dirk Behme , linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 3/4] base: soc: Check for NULL SoC device attributes Date: Tue, 4 Oct 2016 11:09:26 +0200 Message-Id: <1475572167-29581-4-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1475572167-29581-1-git-send-email-geert+renesas@glider.be> References: <1475572167-29581-1-git-send-email-geert+renesas@glider.be> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If soc_device_match() is used to check the value of a specific attribute that is not present for the current SoC, the kernel crashes with a NULL pointer dereference. Fix this by explicitly checking for the absence of a needed property, and considering this a non-match. Signed-off-by: Geert Uytterhoeven Acked-by: Arnd Bergmann --- drivers/base/soc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/base/soc.c b/drivers/base/soc.c index 37c087096b1c5675..545cc9cf2789fe07 100644 --- a/drivers/base/soc.c +++ b/drivers/base/soc.c @@ -185,19 +185,23 @@ static int soc_device_match_one(struct device *dev, void *arg) const struct soc_device_attribute *match = arg; if (match->machine && - !glob_match(match->machine, soc_dev->attr->machine)) + (!soc_dev->attr->machine || + !glob_match(match->machine, soc_dev->attr->machine))) return 0; if (match->family && - !glob_match(match->family, soc_dev->attr->family)) + (!soc_dev->attr->family || + !glob_match(match->family, soc_dev->attr->family))) return 0; if (match->revision && - !glob_match(match->revision, soc_dev->attr->revision)) + (!soc_dev->attr->revision || + !glob_match(match->revision, soc_dev->attr->revision))) return 0; if (match->soc_id && - !glob_match(match->soc_id, soc_dev->attr->soc_id)) + (!soc_dev->attr->soc_id || + !glob_match(match->soc_id, soc_dev->attr->soc_id))) return 0; return 1;