Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4671517imm; Fri, 18 May 2018 08:48:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoz/smjzG/DnnkKsIDGYAbFq1jxEwAw4kg1ggqOpKq+SxLzA/+uYoOyiMTK93oJeRP9tr4Q X-Received: by 2002:a62:8105:: with SMTP id t5-v6mr9911268pfd.215.1526658537832; Fri, 18 May 2018 08:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526658537; cv=none; d=google.com; s=arc-20160816; b=XWOIlK2gxpXCuiWIJJm1zCaZfWDtMFNt+Mc7wLHZy7nLulHlo3Q2gUry0P2Xg0ex4W TZ1tZDq/YJ9KdZi2TEP9i9ewD+yEbaH6tJ2c1bq4KV1ILNPBjeqBga7b5Ypza6t9YaQE +AEyaLyv/3MRQIYFxhqqmQ9A3nzK3uhZ6fTjVFAXApwwfZSfAekjyLdcyI6dRsJv+fai hds43O26tdBDOLpiHdmr0HvKo0HnvLQU1rl7dEuwvxFJGlWGHkjDkRqon8vRqd4E5hOu 5SDnSUPjFxxtyFRU2tXndo7vmBMTlOFM4+F4gkqz9oBT0No5fZsoR3eDs1Ba0fAe3mXi fsZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=ETSuLF/4XmTpR6eUWWTA3QNqtzBoEUpvGe0wkOqjMqU=; b=AEcemWT9q0zTfn6pkwwcksm9B1IGZOgYo0t6Yb3/Au2NVZGu3/kcyrcdd6Dw8EalcP Y9Lp0ua92j/9Me7yFZa8YWw9kiPb/S4MSW2ruRC8cD59xv50Ur648JwEJE113cL+NvVT Eb/5dQRvwrXukorQj4FQuYdElqluP1Uj+5I1FLh0rDeV7Y2B9c/NDjeOi1C73xtd8IqW dvg2e99o8EVnXkOEGq25VS1MK7obKv88wKkB7ok9mGpE7S4zqkvSsjdMZ1y6IUYmeXLQ 8I95QKs9B7u64cHoFQ6qNDq8oECM4ii+HPKlAF9FbX+JULHWnFMFeZoavJKJcssWEGjT bVPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fvnmucTi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u2-v6si7970661plm.379.2018.05.18.08.48.43; Fri, 18 May 2018 08:48:57 -0700 (PDT) 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=@chromium.org header.s=google header.b=fvnmucTi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751994AbeERPsY (ORCPT + 99 others); Fri, 18 May 2018 11:48:24 -0400 Received: from mail-yb0-f194.google.com ([209.85.213.194]:44536 "EHLO mail-yb0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751384AbeERPsV (ORCPT ); Fri, 18 May 2018 11:48:21 -0400 Received: by mail-yb0-f194.google.com with SMTP id s8-v6so1603526ybp.11 for ; Fri, 18 May 2018 08:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ETSuLF/4XmTpR6eUWWTA3QNqtzBoEUpvGe0wkOqjMqU=; b=fvnmucTi462jTrEDnncguTT5lRoL4pv8FZsldNqXoKRFrVEFp//C/2toSZrWhmM1gQ 0G0oFi3UsF5i76j8lzaLnEdm3Wil+V/9InhiQ6digdiwTmrKfqXC9bJSKacEttagep/I VBYx4/vsqNARl9cJwo9AyVgv7Rm33qtdSpOTQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ETSuLF/4XmTpR6eUWWTA3QNqtzBoEUpvGe0wkOqjMqU=; b=hWUVhnOGo/nACNE2N+nvsjVfUJe0i9qzqnH0TgwUsnAlDLSNIaZHJF5fSPbbFCeZcD GqE9ubeIe8ieFR6BHQc9lAdyou1YgPgS4vfUg197zJXYRjOmwzZS8zu5yLdOqCnq95qU iKpp0c5gpZLMGSplLseGTn9b3Cg48cL3ebxtr70Ka6DDunn5meDrCbOU1J7tv65QpeUn LXGlNZDSHSgQXQjiltAH0wWQxtw17Hj5Avx2MmJLiQcifAvlv1EGFM70NKqhM0XpIxYg Pwr47k8vyyojOxvTGZqoU3WMZ/C2NfzOg0d1u0oszYfHEyXDbFew6jEY/Sh0MiJ/1ScK OChg== X-Gm-Message-State: ALKqPwceFl9SZiTnwYmt6dBlc5MyxmIU496soRgTcogO9HSS99UZ3V6E 1UE1rPJo4vAfhFMXg/pTCa/X/g== X-Received: by 2002:a25:6084:: with SMTP id u126-v6mr4923582ybb.288.1526658501091; Fri, 18 May 2018 08:48:21 -0700 (PDT) Received: from localhost ([2620:0:1013:11:ad55:b1db:adfe:3b9f]) by smtp.gmail.com with ESMTPSA id s185-v6sm3126771ywc.37.2018.05.18.08.48.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 May 2018 08:48:20 -0700 (PDT) Date: Fri, 18 May 2018 11:48:19 -0400 From: Sean Paul To: Neil Armstrong Cc: airlied@linux.ie, hans.verkuil@cisco.com, lee.jones@linaro.org, olof@lixom.net, seanpaul@google.com, sadolfsson@google.com, felixe@google.com, bleung@google.com, darekm@google.com, marcheu@chromium.org, fparent@baylibre.com, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/5] media: cec-notifier: Get notifier by device and connector name Message-ID: <20180518154819.GL3373@art_vandelay> References: <1526648704-16873-1-git-send-email-narmstrong@baylibre.com> <1526648704-16873-2-git-send-email-narmstrong@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1526648704-16873-2-git-send-email-narmstrong@baylibre.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 18, 2018 at 03:05:00PM +0200, Neil Armstrong wrote: > In non device-tree world, we can need to get the notifier by the driver > name directly and eventually defer probe if not yet created. > > This patch adds a variant of the get function by using the device name > instead and will not create a notifier if not yet created. > > But the i915 driver exposes at least 2 HDMI connectors, this patch also > adds the possibility to add a connector name tied to the notifier device > to form a tuple and associate different CEC controllers for each HDMI > connectors. > > Signed-off-by: Neil Armstrong Hi Neil, Thanks for posting these! > --- > drivers/media/cec/cec-notifier.c | 11 ++++++++--- > include/media/cec-notifier.h | 27 ++++++++++++++++++++++++--- > 2 files changed, 32 insertions(+), 6 deletions(-) > > diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c > index 16dffa0..dd2078b 100644 > --- a/drivers/media/cec/cec-notifier.c > +++ b/drivers/media/cec/cec-notifier.c > @@ -21,6 +21,7 @@ struct cec_notifier { > struct list_head head; > struct kref kref; > struct device *dev; > + const char *conn; > struct cec_adapter *cec_adap; > void (*callback)(struct cec_adapter *adap, u16 pa); > > @@ -30,13 +31,14 @@ struct cec_notifier { > static LIST_HEAD(cec_notifiers); > static DEFINE_MUTEX(cec_notifiers_lock); > > -struct cec_notifier *cec_notifier_get(struct device *dev) > +struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn) > { > struct cec_notifier *n; > > mutex_lock(&cec_notifiers_lock); > list_for_each_entry(n, &cec_notifiers, head) { > - if (n->dev == dev) { > + if (n->dev == dev && > + (!conn || !strcmp(n->conn, conn))) { > kref_get(&n->kref); > mutex_unlock(&cec_notifiers_lock); > return n; > @@ -46,6 +48,8 @@ struct cec_notifier *cec_notifier_get(struct device *dev) > if (!n) > goto unlock; > n->dev = dev; > + if (conn) > + n->conn = kstrdup(conn, GFP_KERNEL); > n->phys_addr = CEC_PHYS_ADDR_INVALID; > mutex_init(&n->lock); > kref_init(&n->kref); > @@ -54,7 +58,7 @@ struct cec_notifier *cec_notifier_get(struct device *dev) > mutex_unlock(&cec_notifiers_lock); > return n; > } > -EXPORT_SYMBOL_GPL(cec_notifier_get); > +EXPORT_SYMBOL_GPL(cec_notifier_get_conn); > > static void cec_notifier_release(struct kref *kref) > { > @@ -62,6 +66,7 @@ static void cec_notifier_release(struct kref *kref) > container_of(kref, struct cec_notifier, kref); > > list_del(&n->head); > + kfree(n->conn); > kfree(n); > } > > diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h > index cf0add7..814eeef 100644 > --- a/include/media/cec-notifier.h > +++ b/include/media/cec-notifier.h > @@ -20,8 +20,10 @@ struct cec_notifier; > #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) > > /** > - * cec_notifier_get - find or create a new cec_notifier for the given device. > + * cec_notifier_get_conn - find or create a new cec_notifier for the given > + * device and connector tuple. > * @dev: device that sends the events. > + * @conn: the connector name from which the event occurs Probably best to use "name" instead of connector, since it doesn't necessarily _have_ to be a connector name. So, cec_notifier_get_by_name(dev, name) > * > * If a notifier for device @dev already exists, then increase the refcount > * and return that notifier. > @@ -31,7 +33,8 @@ struct cec_notifier; > * > * Return NULL if the memory could not be allocated. > */ > -struct cec_notifier *cec_notifier_get(struct device *dev); > +struct cec_notifier *cec_notifier_get_conn(struct device *dev, > + const char *conn); > > /** > * cec_notifier_put - decrease refcount and delete when the refcount reaches 0. > @@ -85,7 +88,8 @@ void cec_register_cec_notifier(struct cec_adapter *adap, > struct cec_notifier *notifier); > > #else > -static inline struct cec_notifier *cec_notifier_get(struct device *dev) > +static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev, > + const char *conn) > { > /* A non-NULL pointer is expected on success */ > return (struct cec_notifier *)0xdeadfeed; > @@ -121,6 +125,23 @@ static inline void cec_register_cec_notifier(struct cec_adapter *adap, > #endif > > /** > + * cec_notifier_get - find or create a new cec_notifier for the given device. > + * @dev: device that sends the events. > + * > + * If a notifier for device @dev already exists, then increase the refcount > + * and return that notifier. > + * > + * If it doesn't exist, then allocate a new notifier struct and return a > + * pointer to that new struct. You might also want to cover the case where you have multiple named notifiers for the same device. It looks like it just grabs the first one? Sean > + * > + * Return NULL if the memory could not be allocated. > + */ > +static inline struct cec_notifier *cec_notifier_get(struct device *dev) > +{ > + return cec_notifier_get_conn(dev, NULL); > +} > + > +/** > * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID > * > * @n: the CEC notifier > -- > 2.7.4 > -- Sean Paul, Software Engineer, Google / Chromium OS