From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932348Ab2ARR21 (ORCPT ); Wed, 18 Jan 2012 12:28:27 -0500 Received: from mga11.intel.com ([192.55.52.93]:22116 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932200Ab2ARR20 convert rfc822-to-8bit (ORCPT ); Wed, 18 Jan 2012 12:28:26 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.71,315,1320652800"; d="scan'208";a="113656763" From: "Luck, Tony" To: Alan Stern , Greg KH CC: Ingo Molnar , Linus Torvalds , "Rafael J. Wysocki" , "Srivatsa S. Bhat" , Sergei Trofimovich , "linux-kernel@vger.kernel.org" , Kay Sievers , Linux PM mailing list , Borislav Petkov , "tglx@linutronix.de" , "prasad@linux.vnet.ibm.com" , Ming Lei , Djalal Harouni , Borislav Petkov , Hidetoshi Seto , Andi Kleen , "gouders@et.bocholt.fh-gelsenkirchen.de" , Marcos Souza , "justinmattock@gmail.com" , Jeff Chua Subject: RE: [PATCH] mce: fix warning messages about static struct mce_device Thread-Topic: [PATCH] mce: fix warning messages about static struct mce_device Thread-Index: AQHM1J/gZZi9VvM99kKJ1R/CbZ8vIpYQw7OAgAB45YCAASg4AIAAVvMAgAATRoD//5B5gA== Date: Wed, 18 Jan 2012 17:28:23 +0000 Message-ID: <3908561D78D1C84285E8C5FCA982C28F01CF24@ORSMSX104.amr.corp.intel.com> References: <20120118144250.GA16288@suse.de> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.22.254.138] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Greg said: > It was already fixed that way, but the problem is that you can not have > statically allocated 'struct device' objects in the system. and then Alan said: > There's an additional requirement: Device structures may not be reused. > Not even if the caller clears all the fields to 0 in between. That was > the real bug in the original code -- and adding a dummy release routine > wouldn't fix it. There seems to be some curious logic happening here which I don't understand at all. How can the code that deals with 'struct device' tell whether it was statically declared or dynamically allocated? Why would it care? What happens if we play by the rules using a dynamic structure and do device_register() + device_create_file(dev) ... device_remove_file(dev) + device_unregister() then later come back to re-add this and by pure random fluke kzalloc() gives us back the exact same block of memory that we used for dev before? By Alan's logic we are screwed - we are re-using the same device structure (unless kfree() + kzalloc() does some magic pixie dust thing so that this same block of memory is now not the same device structure we had before, even though it has the same address). In summary - I can totally buy the argument that you must start with a zeroed struct device (and that it is just fine that device_unregister() doesn't waste cpu cycles cleaning up the structure just in case someone will re-use it, because that isn't going to be the common case). I just don't understand the magical difference between a static structure that has been memset() to all zero, and a dynamic block returned from kzalloc(). -Tony