Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp663851pxk; Wed, 23 Sep 2020 12:41:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnHEKxfL2njCL6R0kxo5lyguE9zbbaf8cp2YZfBPA5FEzUEh6OPY8MQmqBcTs+4Xp1j2q6 X-Received: by 2002:a05:6402:1558:: with SMTP id p24mr960611edx.194.1600890077667; Wed, 23 Sep 2020 12:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600890077; cv=none; d=google.com; s=arc-20160816; b=Eqj84D1AwvGPeasrZScEGWNoWmwSHHOaawaxIQqB+yaucUoPfXWnFSN8+lsJIHl7jA bqc+GPSlOVswQTySXyLskObLu4E2bgMWPdAL59OA3ofCB/He9RNgjkR5FTaRvQkLfkoG s2Pov5DiB8BY41jwh28RrcchvmBEdYVCLK65u9TqFVpNc3EN0m8cyMi3fvtglS1z4rAq ohYrvTi7ROePW2gQDbP5vw7G+6w4XeXxaF++xlCywY9kcAuuV/L07OdA1cniTHYvAeep +8CdQypch3qOHHmOb7JhPapSFUciZ2SqesaeEEYjcZvjmKOCpbLQ/+ZsyntsJfWHD1/0 QxOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=hcIspOz/xBFrhTBGUdPvbW8fyFPh/S83Nv87zjRg0X4=; b=ar+1PUy8ekx1h0mQ7pWz6oaG/NGD2JmTG93GSw+gAucKo72ijG5r003cAzGHaP/Jkt zadmgSEVe7rdk5PJxOV7ntBA43lqINjvLE289uqsvVMjlRzBiyUGgkzcDUSewi0xCr6Q ndDsdOBjhO5JwzHH6pjTr7IOIciTsE1cFUEcIsfjF+xRvAKInXgVSpbJl2TkOmas3xlZ 8Fm5BkkSvza6aQ9WZ9oqw5nxqsN4RJI6tuJJzqBxgcQTCKMLTMkDYr0SQ4vldxj93nz9 3r/Cv6Ex0tkEDdnF/vUf0VfACQ0PeE3a284cmWfGaPG/iC4FQTTne0tsHlXDuEcSayPo OUJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HiOf6Frb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m16si563066edr.280.2020.09.23.12.40.54; Wed, 23 Sep 2020 12:41:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HiOf6Frb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726620AbgIWThu (ORCPT + 99 others); Wed, 23 Sep 2020 15:37:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbgIWThu (ORCPT ); Wed, 23 Sep 2020 15:37:50 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCAAFC0613D1 for ; Wed, 23 Sep 2020 12:37:49 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id 77so1233811lfj.0 for ; Wed, 23 Sep 2020 12:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hcIspOz/xBFrhTBGUdPvbW8fyFPh/S83Nv87zjRg0X4=; b=HiOf6Frb3msBXibmsvCbJwZbkQY7kDjQTspDr8g6tOESvCgg0fWnhSjB3U8Y5f5qQq REG4i0JcYRqtw9yn+QnSOHyMw8weTSZl8IccFH5UZsP4MDZLjvFximMh3JefbS8B7HCX IiBULzVd4XBWT6ddpbh/gfOj15yege25LYJmKvjEEVaioYYiTXQehedcp3WBQOJG4nMe wB9DFza2VrdxRn/00+LULSkiVNiQWAQu8JTuu3ueiNXqV24GetRRKuqw4KKCsWXqNTsL TSEwqYCjcwNUSEeUYexd3bBy3ihCNOMILCshsTwsV4GMH0cSDisTbJdCfWXDPR0u1Qs+ phDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hcIspOz/xBFrhTBGUdPvbW8fyFPh/S83Nv87zjRg0X4=; b=kWijOy/0IPJVvmKjSldKu5owGOXDCEZ8ZB0OULSg97g1SyAQw9u+KlKooIMKgdmdLS sKHzPjgOqL5ifhdQUIX0dXjuGD0MOUsb+ddgXXUyLkkQvxIMquVXhMyEhC0arfFlZko/ P+DVzC6x4CT2YTtxH6ME8jrUH/LwhGnJ3RnsTxKOLsYz6vX/pPe77kYoWPhqkYqGmscg Hz+JgwPbi921x5N5l48k4Nrqg0WmfR+Zx4IXM+shDlZjvc7yQgK48vVazlpUbAsM716Q fHT2OjBxec5ffMbuzMKoFed5g2b9ujVDR6HeTRrwRuJsOcn2calcDbsBq9yPGygnqaYs douw== X-Gm-Message-State: AOAM5324xv3FEOm71RzapBDrHxSyPk8i1uKPlUTJH6+NlFcBdgvaCCMD qt5Vd74KGq8gxdBtLwDTEtbQFcsbWxErmVUVo819iA== X-Received: by 2002:a19:8906:: with SMTP id l6mr496502lfd.136.1600889867707; Wed, 23 Sep 2020 12:37:47 -0700 (PDT) MIME-Version: 1.0 References: <20200923184803.192265-1-gregkh@linuxfoundation.org> In-Reply-To: <20200923184803.192265-1-gregkh@linuxfoundation.org> From: Rajat Jain Date: Wed, 23 Sep 2020 12:37:10 -0700 Message-ID: Subject: Re: [PATCH] platform/x86: intel_pmc_core: do not create a static struct device To: Greg Kroah-Hartman Cc: "Bhardwaj, Rajneesh" , Vishwanath Somayaji , Platform Driver , Linux Kernel Mailing List , Darren Hart , Andy Shevchenko , Maximilian Luz Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 23, 2020 at 11:47 AM Greg Kroah-Hartman wrote: > > A struct device is a dynamic structure, with reference counting. > "Tricking" the kernel to make a dynamic structure static, by working > around the driver core release detection logic, is not nice. > > Because of this, this code has been used as an example for others on > "how to do things", which is just about the worst thing possible to have > happen. > > Fix this all up by making the platform device dynamic and providing a > real release function. > > Cc: Rajneesh Bhardwaj > Cc: Vishwanath Somayaji > Cc: Darren Hart > Cc: Andy Shevchenko > Cc: Rajat Jain > Cc: platform-driver-x86@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Reported-by: Maximilian Luz > Fixes: b02f6a2ef0a1 ("platform/x86: intel_pmc_core: Attach using APCI HID "INT33A1"") > Signed-off-by: Greg Kroah-Hartman Acked-by: Rajat Jain > --- > drivers/platform/x86/intel_pmc_core_pltdrv.c | 26 +++++++++++++------- > 1 file changed, 17 insertions(+), 9 deletions(-) > > diff --git a/drivers/platform/x86/intel_pmc_core_pltdrv.c b/drivers/platform/x86/intel_pmc_core_pltdrv.c > index 731281855cc8..73797680b895 100644 > --- a/drivers/platform/x86/intel_pmc_core_pltdrv.c > +++ b/drivers/platform/x86/intel_pmc_core_pltdrv.c > @@ -20,15 +20,10 @@ > > static void intel_pmc_core_release(struct device *dev) > { > - /* Nothing to do. */ > + kfree(dev); > } > > -static struct platform_device pmc_core_device = { > - .name = "intel_pmc_core", > - .dev = { > - .release = intel_pmc_core_release, > - }, > -}; > +static struct platform_device *pmc_core_device; > > /* > * intel_pmc_core_platform_ids is the list of platforms where we want to > @@ -52,6 +47,8 @@ MODULE_DEVICE_TABLE(x86cpu, intel_pmc_core_platform_ids); > > static int __init pmc_core_platform_init(void) > { > + int retval; > + > /* Skip creating the platform device if ACPI already has a device */ > if (acpi_dev_present("INT33A1", NULL, -1)) > return -ENODEV; > @@ -59,12 +56,23 @@ static int __init pmc_core_platform_init(void) > if (!x86_match_cpu(intel_pmc_core_platform_ids)) > return -ENODEV; > > - return platform_device_register(&pmc_core_device); > + pmc_core_device = kzalloc(sizeof(*pmc_core_device), GFP_KERNEL); > + if (!pmc_core_device) > + return -ENOMEM; > + > + pmc_core_device->name = "intel_pmc_core"; > + pmc_core_device->dev.release = intel_pmc_core_release; > + > + retval = platform_device_register(pmc_core_device); > + if (retval) > + kfree(pmc_core_device); > + > + return retval; > } > > static void __exit pmc_core_platform_exit(void) > { > - platform_device_unregister(&pmc_core_device); > + platform_device_unregister(pmc_core_device); > } > > module_init(pmc_core_platform_init); > -- > 2.28.0 >