From patchwork Mon Nov 7 18:35:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 81167 Delivered-To: patch@linaro.org Received: by 10.182.113.165 with SMTP id iz5csp1266093obb; Mon, 7 Nov 2016 10:35:49 -0800 (PST) X-Received: by 10.98.39.66 with SMTP id n63mr16158263pfn.72.1478543749763; Mon, 07 Nov 2016 10:35:49 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xn10si27186625pab.93.2016.11.07.10.35.49; Mon, 07 Nov 2016 10:35:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933465AbcKGSfh (ORCPT + 27 others); Mon, 7 Nov 2016 13:35:37 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36215 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932791AbcKGSfW (ORCPT ); Mon, 7 Nov 2016 13:35:22 -0500 Received: by mail-pf0-f194.google.com with SMTP id n85so16775671pfi.3 for ; Mon, 07 Nov 2016 10:35:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=rME73+i0mEVSBuQLs/dCRIXAjGJekVuqUUCM3NBEdBk=; b=nnu5xqzV8tpSzoztPBMGifBaa+EUp3f1EkfXMqiRF6kv5ML9bnwT8V00F4Uq1+9mj1 k1fiz990Rys3ByRXl755opwkKalauofIu+zvyHngt0MLpNnxdpEDhKQ1BZPAQ6DH/S+M RDKEGMZS71cf/0AVp5dnDiMkn5fFisS+/YSyU2khGM4WQu/4oFVg1SOSJa1nr9xQmJG+ L4xK2yxJ7tceipxZWB5Jb1f+Sn4aoCgoruNGgRV12Hv2+EQ7zuPEGaj9EpetOstRVBBD rYSq1Eo3jhW8XIKsufLpmMNXT6Nu44jfHKmSRZaO7Qdy34Z8itx23lO7IfcZ8Y3VK3xz Bv9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=rME73+i0mEVSBuQLs/dCRIXAjGJekVuqUUCM3NBEdBk=; b=JmbbJ9/mmM9XAOlGtQRgkSR08Xsvd6AO8fYUXfueR6679IjfGunT+pbkslHDuTvIIi 72knY5aydGIHNa09WaP3GWDg/YJ48MlNOEaNvK8hgL2NJlhzSJEt/D2lvVJOQbSHOf5V BbqXspJOEqWMA4fWzUJHEqp8uDEOkRGFnDUxkIqxxabClx7/2EtsAZQHAyL0OG5bcxdv HzplSNhVd0SdxqCpaLbB5jSCU23F8u7y00ovUvjMo+wTP2VvupKQN/tSJuYkC3WmuNT9 j/QELxG/YcMnwqp+7q85C8n4AvkswX9zXlBpHd4T2S6Zd/YaPCUOfJkVEZmIbxi3vgNx qfSw== X-Gm-Message-State: ABUngve0+YwziZp8oMlqc0DJsgaJ2+c9u1sHScVz5VVOR636OCltoLbjS02tHBZp7GI85g== X-Received: by 10.98.102.22 with SMTP id a22mr15801137pfc.182.1478543716753; Mon, 07 Nov 2016 10:35:16 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id b126sm12905078pfg.90.2016.11.07.10.35.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 10:35:15 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 2BF866A7E; Mon, 7 Nov 2016 12:35:14 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 7C223300079; Mon, 7 Nov 2016 11:35:13 -0700 (MST) From: minyard@acm.org To: Corentin Labbe Cc: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Corey Minyard Subject: [PATCH] Move platform device creation earlier in the initialization Date: Mon, 7 Nov 2016 12:35:10 -0600 Message-Id: <1478543711-1132-1-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20161107095744.GA20037@Red> References: <20161107095744.GA20037@Red> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corey Minyard Some logs are printed out early using smi->dev, but on a platform device that is not created until later. So move the creation of that device structure earlier in the sequence so it can be used for printing. Signed-off-by: Corey Minyard --- Corentin, can you try the attached patch? It moves the platform device allocation earlier, but I don't really want to actually add the platform device until later. drivers/char/ipmi/ipmi_si_intf.c | 46 +++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 15 deletions(-) -- 2.7.4 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c index cb45108..751c281 100644 --- a/drivers/char/ipmi/ipmi_si_intf.c +++ b/drivers/char/ipmi/ipmi_si_intf.c @@ -3502,6 +3502,7 @@ static int try_smi_init(struct smi_info *new_smi) { int rv = 0; int i; + char *init_name = NULL; printk(KERN_INFO PFX "Trying %s-specified %s state" " machine at %s address 0x%lx, slave address 0x%x," @@ -3531,6 +3532,26 @@ static int try_smi_init(struct smi_info *new_smi) goto out_err; } + /* Do this early so it's available for logs. */ + if (!new_smi->dev) { + init_name = kasprintf(GFP_KERNEL, "ipmi_si.%d", 0); + + /* + * If we don't already have a device from something + * else (like PCI), then register a new one. + */ + new_smi->pdev = platform_device_alloc("ipmi_si", + new_smi->intf_num); + if (!new_smi->pdev) { + pr_err(PFX "Unable to allocate platform device\n"); + goto out_err; + } + new_smi->dev = &new_smi->pdev->dev; + new_smi->dev->driver = &ipmi_driver.driver; + /* Nulled by device_add() */ + new_smi->dev->init_name = init_name; + } + /* Allocate the state machine's data and initialize it. */ new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL); if (!new_smi->si_sm) { @@ -3604,21 +3625,7 @@ static int try_smi_init(struct smi_info *new_smi) atomic_set(&new_smi->req_events, 1); } - if (!new_smi->dev) { - /* - * If we don't already have a device from something - * else (like PCI), then register a new one. - */ - new_smi->pdev = platform_device_alloc("ipmi_si", - new_smi->intf_num); - if (!new_smi->pdev) { - printk(KERN_ERR PFX - "Unable to allocate platform device\n"); - goto out_err; - } - new_smi->dev = &new_smi->pdev->dev; - new_smi->dev->driver = &ipmi_driver.driver; - + if (new_smi->pdev) { rv = platform_device_add(new_smi->pdev); if (rv) { printk(KERN_ERR PFX @@ -3668,6 +3675,9 @@ static int try_smi_init(struct smi_info *new_smi) dev_info(new_smi->dev, "IPMI %s interface initialized\n", si_to_str[new_smi->si_type]); + WARN_ON(new_smi->dev->init_name != NULL); + kfree(init_name); + return 0; out_err_stop_timer: @@ -3712,8 +3722,14 @@ static int try_smi_init(struct smi_info *new_smi) if (new_smi->dev_registered) { platform_device_unregister(new_smi->pdev); new_smi->dev_registered = false; + new_smi->pdev = NULL; + } else if (new_smi->pdev) { + platform_device_put(new_smi->pdev); + new_smi->pdev = NULL; } + kfree(init_name); + return rv; }