Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp481630ybl; Tue, 28 Jan 2020 06:38:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxIe5s9udF0RnkvdLjJFRlHhrR8BbnFhhegFnioqIgYlAggdV4zvUfOu7sKjmEO8JU0wFoc X-Received: by 2002:aca:c7cb:: with SMTP id x194mr3064771oif.157.1580222287150; Tue, 28 Jan 2020 06:38:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580222287; cv=none; d=google.com; s=arc-20160816; b=S2rWFElII6rIpGS/m0xMjLT9/XTv7eMkVX6mI6nv+cBM0nR/xJh2oflipdvh1G3h2i OVkC3eqRD3DrAdwu+y+VhFWrfLR1MylHds/2c54RXpE29UElqzB30fTLM+jEFyCFf2Q2 d/KdD4HwE1Dx7W9prODCbKGgacBed14WFCZ6fSAqgUQ0NDr4Nkxew+/IjK62Ax9gurGe aK+z4aVgWRWYsRKXZXkTfPIZ4YGLTKfVXlWDgPyQ1RngerLAqGKQg3MEjhD303yjedsV Z56EPEGG4NblFzTsi3VIf65G8YWJzKBPy8a0y5Y4vB4F351mPwwjDxR/9vqfa0dWmlWR wKRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dw0u59HgS4vBxhtY/W5l3uNy+vg7xccm559sF+IcADw=; b=dYh0eQFiVnWMCOE96VGZYZMu7FDiUKYrPFJ8Wqwd4BKxN2kXp8YrHayb3MeyVV8flR ibhRLw0ZUKJZjJn7qhzQeW/2fBbZEqdKKFhqavQDMndO/d0hnfqglRGm5rfp/JYY7UaY 9IqxUL9znYPyp48iX5B9pT4L3pb0xJ4S00CTOkeRX8ygXLZUrQsW1teghtDScMHkvSXd VVotIOnMfp5QQjQ4oPnZpAvVfAb4+Rp8sQXznwK61HxSHYQdqq6CXB6Jmh4LahPtcMLQ 58b2qy5zTLk1ELKCeQxw+3pa9PbleG+yxw1zoOat4wwZeC3urGc9J0l7lHUIx72n75El EWOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Gdl5uPJd; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si5201925oic.72.2020.01.28.06.37.55; Tue, 28 Jan 2020 06:38:07 -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=pass header.i=@kernel.org header.s=default header.b=Gdl5uPJd; 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 S1731432AbgA1OVx (ORCPT + 99 others); Tue, 28 Jan 2020 09:21:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:47340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730917AbgA1OVw (ORCPT ); Tue, 28 Jan 2020 09:21:52 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7CA1824686; Tue, 28 Jan 2020 14:21:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221310; bh=IwRh4MwwKbEAJczjkT6p7Y8EFA00nRALELVHg28Gjt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gdl5uPJdzOg6Z0uILQKqCgHjs1bWQ/9pk3ZrZ+VlHdRti+8WH76STKE3MRreRbuiy mw6af7d7/Bo/gWNSQp1DdFdGWfIVN/h0P6LeVrrhOChQlQN3xXLm4jWlcFv77TIcJY DkpUIhEiJc9H4fOeaMg8P2+umzampk01NOTwdCGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Sasha Levin Subject: [PATCH 4.9 173/271] mic: avoid statically declaring a struct device. Date: Tue, 28 Jan 2020 15:05:22 +0100 Message-Id: <20200128135905.441816132@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann [ Upstream commit bc83f79bd2119230888fb8574639d5a51b38f903 ] Generally, declaring a platform device as a static variable is a bad idea and can cause all kinds of problems, in particular with the DMA configuration and lifetime rules. A specific problem we hit here is from a bug in clang that warns about certain (otherwise valid) macros when used in static variables: drivers/misc/mic/card/mic_x100.c:285:27: warning: shift count >= width of type [-Wshift-count-overflow] static u64 mic_dma_mask = DMA_BIT_MASK(64); ^~~~~~~~~~~~~~~~ include/linux/dma-mapping.h:141:54: note: expanded from macro 'DMA_BIT_MASK' #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1)) ^ ~~~ A slightly better way here is to create the platform device dynamically and set the dma mask in the probe function. This avoids the warning and some other problems, but is still not ideal because the device creation should really be separated from the driver, and the fact that the device has no parent means we have to force the dma mask rather than having it set up from the bus that the device is actually on. Fixes: dd8d8d44df64 ("misc: mic: MIC card driver specific changes to enable SCIF") Signed-off-by: Arnd Bergmann Link: https://lore.kernel.org/r/20190712092426.872625-1-arnd@arndb.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/mic/card/mic_x100.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/misc/mic/card/mic_x100.c b/drivers/misc/mic/card/mic_x100.c index b9f0710ffa6b0..4007adc666f37 100644 --- a/drivers/misc/mic/card/mic_x100.c +++ b/drivers/misc/mic/card/mic_x100.c @@ -249,6 +249,9 @@ static int __init mic_probe(struct platform_device *pdev) mdrv->dev = &pdev->dev; snprintf(mdrv->name, sizeof(mic_driver_name), mic_driver_name); + /* FIXME: use dma_set_mask_and_coherent() and check result */ + dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + mdev->mmio.pa = MIC_X100_MMIO_BASE; mdev->mmio.len = MIC_X100_MMIO_LEN; mdev->mmio.va = devm_ioremap(&pdev->dev, MIC_X100_MMIO_BASE, @@ -294,18 +297,6 @@ static void mic_platform_shutdown(struct platform_device *pdev) mic_remove(pdev); } -static u64 mic_dma_mask = DMA_BIT_MASK(64); - -static struct platform_device mic_platform_dev = { - .name = mic_driver_name, - .id = 0, - .num_resources = 0, - .dev = { - .dma_mask = &mic_dma_mask, - .coherent_dma_mask = DMA_BIT_MASK(64), - }, -}; - static struct platform_driver __refdata mic_platform_driver = { .probe = mic_probe, .remove = mic_remove, @@ -315,6 +306,8 @@ static struct platform_driver __refdata mic_platform_driver = { }, }; +static struct platform_device *mic_platform_dev; + static int __init mic_init(void) { int ret; @@ -328,9 +321,12 @@ static int __init mic_init(void) request_module("mic_x100_dma"); mic_init_card_debugfs(); - ret = platform_device_register(&mic_platform_dev); + + mic_platform_dev = platform_device_register_simple(mic_driver_name, + 0, NULL, 0); + ret = PTR_ERR_OR_ZERO(mic_platform_dev); if (ret) { - pr_err("platform_device_register ret %d\n", ret); + pr_err("platform_device_register_full ret %d\n", ret); goto cleanup_debugfs; } ret = platform_driver_register(&mic_platform_driver); @@ -341,7 +337,7 @@ static int __init mic_init(void) return ret; device_unregister: - platform_device_unregister(&mic_platform_dev); + platform_device_unregister(mic_platform_dev); cleanup_debugfs: mic_exit_card_debugfs(); done: @@ -351,7 +347,7 @@ done: static void __exit mic_exit(void) { platform_driver_unregister(&mic_platform_driver); - platform_device_unregister(&mic_platform_dev); + platform_device_unregister(mic_platform_dev); mic_exit_card_debugfs(); } -- 2.20.1