From patchwork Wed May 18 15:27:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milton Miller X-Patchwork-Id: 96188 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 406D91007D5 for ; Thu, 19 May 2011 01:27:43 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756672Ab1ERP1l (ORCPT ); Wed, 18 May 2011 11:27:41 -0400 Received: from mail4.comsite.net ([205.238.176.238]:63160 "EHLO mail4.comsite.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755225Ab1ERP1k (ORCPT ); Wed, 18 May 2011 11:27:40 -0400 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=71.22.127.106; Received: from mdm.bga.com (unverified [71.22.127.106]) by mail4.comsite.net (Comsite International, Inc. Advanced E-Mail Services) with ESMTP id 10218236-1844257 for multiple; Wed, 18 May 2011 10:27:39 -0500 From: Milton Miller To: Grant Likely Cc: David Miller , , , In-Reply-To: References: <20110517.134312.226762699.davem@davemloft.net> Subject: [PATCH] of: fix race when matching drivers Date: Wed, 18 May 2011 10:27:39 -0500 X-Originating-IP: 71.22.127.106 Message-ID: <1305732459_6563@mail4.comsite.net> X-HeloNotChecked: Helo response was not checked before commands sent Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org If two drivers are probing devices at the same time, both will write their match table result to the dev->of_match cache at the same time. Only write the result if the device matches. In a thread titled "SBus devices sometimes detected, sometimes not", Meelis reported his SBus hme was not detected about 50% of the time. From the debug suggested by Grant it was obvious another driver matched some devices between the call to match the hme and the hme discovery failling. Reported-by: Meelis Roos Signed-off-by: Milton Miller --- Grant, I really think this of_match cache in the device node is bad a bad tradeoff, and am willing to submit patches to remove it for 2.6.40. It is only used by about 26 drivers and all use it once during probe to fill out their driver data. It comes at the cost of a long for every struct device in every system. I'll even offer to throw in a patch to cache the parsing of the compatible property to speed up of_device_is_compatible if needed. -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: work.git/include/linux/of_device.h =================================================================== --- work.git.orig/include/linux/of_device.h 2011-05-18 09:57:01.014386816 -0500 +++ work.git/include/linux/of_device.h 2011-05-18 09:58:27.537431575 -0500 @@ -21,8 +21,15 @@ extern void of_device_make_bus_id(struct static inline int of_driver_match_device(struct device *dev, const struct device_driver *drv) { - dev->of_match = of_match_device(drv->of_match_table, dev); - return dev->of_match != NULL; + const struct of_device_id *match; + + match = of_match_device(drv->of_match_table, dev); + if (match) { + dev->of_match = of_match_device(drv->of_match_table, dev); + return 1; + } + + return 0; } extern struct platform_device *of_dev_get(struct platform_device *dev);