Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1557228pxb; Sun, 17 Jan 2021 13:28:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3nKuHL1lOQGYxOxPOmWb1fwS8LmKoN6eSlBFIz92SNg8rtEY8Pvv2FTOrpfj1HQ97IKvV X-Received: by 2002:a50:8a62:: with SMTP id i89mr16880901edi.388.1610918913975; Sun, 17 Jan 2021 13:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610918913; cv=none; d=google.com; s=arc-20160816; b=0CnZum07uuMD7tjWvJfJUglRuDZSteyA/dSikADIcymDTrhkH4kHlc0C4xEMCfiMWI dQMyWd0Z14kjQW7yRMTfpkrSzmsb6Zl6lReQ/+56amilfXEnK8KH90yp2SChEpsdWxQ1 //yVj5VNAMdEcmshxGwmqQfKOL4wcFWznGgpcS4u3hW3vbKoObAwR4w5GHyK3F6UaENX ugsTWajZsrEgoXXEX0e7Q39eCB+eje4o6ZTYOuxK0fBC1fIEHcnzI9n/fZhZfCDJjtOE Aq1f0iGdv6fyKoH/hBjzsnnKUWYXLTqaxl2eg4UFtO0dElQjjtf5RQG2hmm2IjZX6eqI 6iUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IOaqbIKSRS9ckIeSaq3IkbuULYGxEaXINEMbw0LKySc=; b=BDY7DfoNl0BjGNxdHnKsWb2e5td5RtwrvqCdPdij9n4/XFTaKv5Wgjt5AxAxcBq2Fo QndBqVvazKMZ0Ns+Aa3iQGkCeC52+tX/PykFtJBJFX5EDGqxuW2TjwqpWda5mJ1XaVU1 3aJ1PsPyKKrPImKPwNM/UjoaKiq2hj9Lq4+tktd0rBOrhUfnlxZiGfYXOnBs2q0nZ4H/ 8ZyQDAsyTSa+sdJ8eOy7MDr9XKtTYp+sfHpEhc/qc0e7R9Fd7vHH8BU84bjrawgw+Atk RlkjjuIkjKCeUkfwxos8n5Jlei8lJg9DMMEtrZdoemWwqVuUZ4MEAoRN4p+NVW8Nc+eC U0ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GdsAz8rw; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v8si6982332edc.382.2021.01.17.13.28.11; Sun, 17 Jan 2021 13:28:33 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=GdsAz8rw; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729739AbhAQVYk (ORCPT + 99 others); Sun, 17 Jan 2021 16:24:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50777 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729666AbhAQVYh (ORCPT ); Sun, 17 Jan 2021 16:24:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610918588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IOaqbIKSRS9ckIeSaq3IkbuULYGxEaXINEMbw0LKySc=; b=GdsAz8rweql3dDWoLIFKjXEDbAIRT2rLHt1gzqFMU1PgrHMXJ4ep71K9LZel23oB3R1Zxe sbklAQywUE3f6aDzSSCm/7BI66mEsbYhPF+3VC//wFUzzlEsFufU7tji2nP9PASeW7d3RA /mkYH84Z+Uv4M6DOcbAZEuREYDohdjQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-283-__A6O-G6N9ifoupu4dAKPA-1; Sun, 17 Jan 2021 16:23:03 -0500 X-MC-Unique: __A6O-G6N9ifoupu4dAKPA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5026A107ACE4; Sun, 17 Jan 2021 21:23:01 +0000 (UTC) Received: from x1.localdomain.com (ovpn-112-7.ams2.redhat.com [10.36.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24B151002388; Sun, 17 Jan 2021 21:22:58 +0000 (UTC) From: Hans de Goede To: Lee Jones , Cezary Rojewski , Pierre-Louis Bossart , Liam Girdwood , Jie Yang , Mark Brown Cc: Hans de Goede , patches@opensource.cirrus.com, linux-kernel@vger.kernel.org, Andy Shevchenko , Charles Keepax , alsa-devel@alsa-project.org Subject: [PATCH v3 2/5] mfd: arizona: Replace arizona_of_get_type() with device_get_match_data() Date: Sun, 17 Jan 2021 22:22:49 +0100 Message-Id: <20210117212252.206115-3-hdegoede@redhat.com> In-Reply-To: <20210117212252.206115-1-hdegoede@redhat.com> References: <20210117212252.206115-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace the custom arizona_of_get_type() function with the generic device_get_match_data() helper. Besides being a nice cleanup this also makes it easier to add support for binding to ACPI enumerated devices. While at it also fix a possible NULL pointer deref of the id argument to the probe functions (this could happen on e.g. manual driver binding through sysfs). Suggested-by: Andy Shevchenko Signed-off-by: Hans de Goede --- Changes in v2: - New patch in v2 of this patchset --- drivers/mfd/arizona-core.c | 11 ----------- drivers/mfd/arizona-i2c.c | 10 ++++++---- drivers/mfd/arizona-spi.c | 10 ++++++---- drivers/mfd/arizona.h | 9 --------- 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c index 000cb82023e3..75f1bc671d59 100644 --- a/drivers/mfd/arizona-core.c +++ b/drivers/mfd/arizona-core.c @@ -797,17 +797,6 @@ const struct dev_pm_ops arizona_pm_ops = { EXPORT_SYMBOL_GPL(arizona_pm_ops); #ifdef CONFIG_OF -unsigned long arizona_of_get_type(struct device *dev) -{ - const struct of_device_id *id = of_match_device(arizona_of_match, dev); - - if (id) - return (unsigned long)id->data; - else - return 0; -} -EXPORT_SYMBOL_GPL(arizona_of_get_type); - static int arizona_of_get_core_pdata(struct arizona *arizona) { struct arizona_pdata *pdata = &arizona->pdata; diff --git a/drivers/mfd/arizona-i2c.c b/drivers/mfd/arizona-i2c.c index 2a4a3a164d0a..5e83b730c4ce 100644 --- a/drivers/mfd/arizona-i2c.c +++ b/drivers/mfd/arizona-i2c.c @@ -23,14 +23,16 @@ static int arizona_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { + const void *match_data; struct arizona *arizona; const struct regmap_config *regmap_config = NULL; - unsigned long type; + unsigned long type = 0; int ret; - if (i2c->dev.of_node) - type = arizona_of_get_type(&i2c->dev); - else + match_data = device_get_match_data(&i2c->dev); + if (match_data) + type = (unsigned long)match_data; + else if (id) type = id->driver_data; switch (type) { diff --git a/drivers/mfd/arizona-spi.c b/drivers/mfd/arizona-spi.c index 704f214d2614..798b88295c77 100644 --- a/drivers/mfd/arizona-spi.c +++ b/drivers/mfd/arizona-spi.c @@ -23,14 +23,16 @@ static int arizona_spi_probe(struct spi_device *spi) { const struct spi_device_id *id = spi_get_device_id(spi); + const void *match_data; struct arizona *arizona; const struct regmap_config *regmap_config = NULL; - unsigned long type; + unsigned long type = 0; int ret; - if (spi->dev.of_node) - type = arizona_of_get_type(&spi->dev); - else + match_data = device_get_match_data(&spi->dev); + if (match_data) + type = (unsigned long)match_data; + else if (id) type = id->driver_data; switch (type) { diff --git a/drivers/mfd/arizona.h b/drivers/mfd/arizona.h index 995efc6d7f32..801cbbcd71cb 100644 --- a/drivers/mfd/arizona.h +++ b/drivers/mfd/arizona.h @@ -50,13 +50,4 @@ int arizona_dev_exit(struct arizona *arizona); int arizona_irq_init(struct arizona *arizona); int arizona_irq_exit(struct arizona *arizona); -#ifdef CONFIG_OF -unsigned long arizona_of_get_type(struct device *dev); -#else -static inline unsigned long arizona_of_get_type(struct device *dev) -{ - return 0; -} -#endif - #endif -- 2.28.0