Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp559144imm; Tue, 15 May 2018 05:56:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpMJqnXMKI0r7HvDoL/wjd/z732dx6B8k0SzpnxLbrxuYMWSOJarz6naDukZfxM4BEXk60I X-Received: by 2002:a63:6016:: with SMTP id u22-v6mr12120551pgb.284.1526389007599; Tue, 15 May 2018 05:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526389007; cv=none; d=google.com; s=arc-20160816; b=ym9QAOdFrhJRSTT2atIHsx+wfqr/XBbbbQDTWT4AjBFRoyx60HK4OTj7eZEA32pAUd Pjst8aM30rkPu7gtt/V3VSdezO5iCz8Pe+iH7JG4v5GVy11MiXPPHPpGDnvOaGyMiaWD y03OL9bKS/H4xET2EzSV658eUy8/n8dSTcRnpb/0GMFbn3PG43opcZYvqT+KYHylgirK q3bm3zL5vaiMtZaEs5No6tdD9KpfajJdbh2M9UG6qGIRxi47wRy8niaa30hFnn6ENKwg L2EMv98riitB5fKOWXuFJa1qTbhxwxU8R8zccrI0m3WeZQo0o9z2LXwnGxQw6tfrlJVF ZMNw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=q66HFJH+ZL5Rmh+Pcy1hk4eu9n6NWmJ2t2NwU4Gg36I=; b=U2pWuDLxEDGcsk1MB8+AEf2ELdIeMQVC/UHVZ0i8bfHIscK/lSCvARixaZY5D1Famf GY3DheF986oAGgNX/I+wPr7KwQ/RPR+haLi0FcivMNFKqZpVsLd0wBxq59lbE0hi3LPW Q4pWe+WqGGcD59eQ3xVQGmy0EagNEFy+ICOJdxCskIbv4Seic5DhV4OECcOgCqOb85jI lYVQiH26idaeoUVFo6Tdtj/nROg/JHxifSwQg8EwnjBKcehHRNJ5DxvpYYOMCw+yMaZI yc5FJbSddtWJrTnecoNToRxpOnd+87rBLWknU2hPpTi1HzPhcVVjiyHFzQ2MIIaxNFyx yTNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=mi/Ob3zQ; 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=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h14-v6si11831027pfj.178.2018.05.15.05.56.25; Tue, 15 May 2018 05:56:47 -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=@cisco.com header.s=iport header.b=mi/Ob3zQ; 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=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753043AbeEOMyT (ORCPT + 99 others); Tue, 15 May 2018 08:54:19 -0400 Received: from aer-iport-4.cisco.com ([173.38.203.54]:3782 "EHLO aer-iport-4.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752563AbeEOMyO (ORCPT ); Tue, 15 May 2018 08:54:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=5057; q=dns/txt; s=iport; t=1526388854; x=1527598454; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=bZ9Uq2djskwA0EUwmLOqWW89ctg+PiivN1tAHn3dTUM=; b=mi/Ob3zQDdg9r7DYeQPXVMsiJ45pOEsSc6bLU46tOFOlMtJ8actFm/o8 3GUBpWZbT0bqDXcJLSGfbaR3vskcQRpstI+9Pezlh5jb5HdoPnSCTDIVf rzhvFnFM3QkWhqB0kr7uiTmpsazIHq0RHsC6aAdIleW6Xu6O5bTzMzzID Y=; X-IronPort-AV: E=Sophos;i="5.49,403,1520899200"; d="scan'208";a="3795011" Received: from aer-iport-nat.cisco.com (HELO aer-core-1.cisco.com) ([173.38.203.22]) by aer-iport-4.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 May 2018 12:54:12 +0000 Received: from [10.47.79.81] ([10.47.79.81]) (authenticated bits=0) by aer-core-1.cisco.com (8.14.5/8.14.5) with ESMTP id w4FCsBbG011103 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 15 May 2018 12:54:11 GMT Subject: Re: [PATCH 1/5] media: cec-notifier: Get notifier by device and connector name To: Neil Armstrong , airlied@linux.ie, hans.verkuil@cisco.com, lee.jones@linaro.org, olof@lixom.net, seanpaul@google.com Cc: 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 References: <1526388421-18808-1-git-send-email-narmstrong@baylibre.com> <1526388421-18808-2-git-send-email-narmstrong@baylibre.com> From: Hans Verkuil Message-ID: <13501ccd-b346-4eb8-49c8-a92d85e3e5df@cisco.com> Date: Tue, 15 May 2018 14:54:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1526388421-18808-2-git-send-email-narmstrong@baylibre.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-User: hansverk Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Neil, Two small comments below: On 05/15/18 14:46, 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 > --- > drivers/media/cec/cec-notifier.c | 12 +++++++++--- > include/media/cec-notifier.h | 30 ++++++++++++++++++++++++++++-- > 2 files changed, 37 insertions(+), 5 deletions(-) > > diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c > index 16dffa0..7038abae1 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,8 @@ static void cec_notifier_release(struct kref *kref) > container_of(kref, struct cec_notifier, kref); > > list_del(&n->head); > + if (n->conn) No need for this if, kfree already tests the pointer. > + kfree(n->conn); > kfree(n); > } > > diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h > index cf0add7..73f92c7 100644 > --- a/include/media/cec-notifier.h > +++ b/include/media/cec-notifier.h > @@ -20,6 +20,23 @@ struct cec_notifier; > #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) > > /** > + * 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 > + * > + * 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. > + * > + * Return NULL if the memory could not be allocated. > + */ > +struct cec_notifier *cec_notifier_get_conn(struct device *dev, > + const char *conn); > + > +/** > * cec_notifier_get - find or create a new cec_notifier for the given device. > * @dev: device that sends the events. > * > @@ -31,7 +48,10 @@ struct cec_notifier; > * > * Return NULL if the memory could not be allocated. > */ > -struct cec_notifier *cec_notifier_get(struct device *dev); > +static inline struct cec_notifier *cec_notifier_get(struct device *dev) > +{ > + return cec_notifier_get_conn(dev, NULL); > +} > > /** > * cec_notifier_put - decrease refcount and delete when the refcount reaches 0. > @@ -85,12 +105,18 @@ 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; > } > > +static inline struct cec_notifier *cec_notifier_get(struct device *dev) > +{ > + return cec_notifier_get_conn(dev, NULL); > +} Just move this function to after the #if ... #else ... #endif After all, it is the same static inline for both. > + > static inline void cec_notifier_put(struct cec_notifier *n) > { > } > Regards, Hans