From patchwork Thu Apr 10 22:59:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 3965101 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0595E9F3D5 for ; Thu, 10 Apr 2014 22:59:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 35E9A202FF for ; Thu, 10 Apr 2014 22:59:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 090C720259 for ; Thu, 10 Apr 2014 22:59:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759191AbaDJW7f (ORCPT ); Thu, 10 Apr 2014 18:59:35 -0400 Received: from mail-la0-f52.google.com ([209.85.215.52]:50874 "EHLO mail-la0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753823AbaDJW7e (ORCPT ); Thu, 10 Apr 2014 18:59:34 -0400 Received: by mail-la0-f52.google.com with SMTP id ec20so2808354lab.39 for ; Thu, 10 Apr 2014 15:59:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:subject:cc:from:organization:date :mime-version:content-type:content-transfer-encoding:message-id; bh=QXXY8j+/Q5pM6/84nEGI4eEo/oG1xodOQZLhaChQcvw=; b=IqzdmOuT32HXWwV1AtQLX0hLPtLohjwKeh5pncZS+QkVxUA8aoDccoliJV+J9wHcT8 GLGJaHaZda+stkQ3OONrFKy55x2pWe7m2SlWF4IaefjJB0fxRT8UWssdHhfPmjWxYSAZ yXGax0iRCt41vUNDsBlWYao2sFWJhrcNrU0BHr0x4RlrXK2EnQ9QaYblaWiC7S/+V+ci G8CRIHfRpQ9RUdmC+4z9AuUJ8vvSqPmkr6Nwe/nafW/mACfcuyyDevSao2fMw2k7wHdq 3wnxgv7J3WdY8BrFicNyUEnJIVunisn/t22LanFRwBVR2E8U8h4fBXisrVa7w/kcUd1q Tp1A== X-Gm-Message-State: ALoCoQljV3gpy6LDh+0VLFvJtLJa+VnuA43GL1zw/EWQGQzHIrmipoVnHt7sscVNYVTlX8AMLgm/ X-Received: by 10.152.239.137 with SMTP id vs9mr26877lac.59.1397170773077; Thu, 10 Apr 2014 15:59:33 -0700 (PDT) Received: from wasted.cogentembedded.com (ppp85-140-137-254.pppoe.mtu-net.ru. [85.140.137.254]) by mx.google.com with ESMTPSA id zf7sm5396059lab.7.2014.04.10.15.59.32 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 10 Apr 2014 15:59:32 -0700 (PDT) To: kishon@ti.com Subject: [PATCH] phy: fix kernel oops in phy_lookup() Cc: linux-sh@vger.kernel.org, magnus.damm@gmail.com, linux-kernel@vger.kernel.org From: Sergei Shtylyov Organization: Cogent Embedded Date: Fri, 11 Apr 2014 02:59:42 +0400 MIME-Version: 1.0 Message-Id: <201404110259.43282.sergei.shtylyov@cogentembedded.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The kernel oopses in phy_lookup() due to 'phy->init_data' being NULL if we register PHYs from a device tree probing driver and then call phy_get() on a device that has no representation in the device tree (e.g. a PCI device). Checking the pointer before dereferening it and skipping an interation if it's NULL prevents this kernel oops. Signed-off-by: Sergei Shtylyov --- The patch is against the 'fixes' branch of Kishon's 'linux-phy.git' repo. drivers/phy/phy-core.c | 3 +++ 1 file changed, 3 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-phy/drivers/phy/phy-core.c =================================================================== --- linux-phy.orig/drivers/phy/phy-core.c +++ linux-phy/drivers/phy/phy-core.c @@ -64,6 +64,9 @@ static struct phy *phy_lookup(struct dev class_dev_iter_init(&iter, phy_class, NULL, NULL); while ((dev = class_dev_iter_next(&iter))) { phy = to_phy(dev); + + if (!phy->init_data) + continue; count = phy->init_data->num_consumers; consumers = phy->init_data->consumers; while (count--) {