Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1873880imm; Thu, 24 May 2018 02:06:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoPvarv3sDt5ROQco1/j11opGJB7QaujZTogpWIrQFe70qp2WZ7BO8E9cgDVGmcdj4WgJTO X-Received: by 2002:a63:2a89:: with SMTP id q131-v6mr5065027pgq.379.1527152775103; Thu, 24 May 2018 02:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527152775; cv=none; d=google.com; s=arc-20160816; b=A0Q6uPy0b2VNT//lyeI+Y1ZROjSniJvnBuA+ncwKNTsg0aPsi9wSzE8qOtRicZ5bui dSrTzPnFWXGYzOID25x+0mLMLEaAYG4AIsmygu0cJ97CdET8IpmUn6QsXvrHzz/XOzQT AHapszQU9/4uH3AH577bcWgzUpva3xna3N5rVIZkqHy1q6AA0IZmwPDqRzevYqLy8DVH tbELB4M4aB72B4M5aewUFZp33/MNhn+gpchcWGk42vrjSEChnE7XUIH5ajssh6rtaxc5 FNQuk+MibUwiCiCLwLFgm1zPdCubhfRUzaCcJ8uzFuytmR1+f7JYo8mZclX3AbBuXmwL V9jQ== 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:arc-authentication-results; bh=kQ9SDeq1FS3lm3ujxmgqxx7TjO3hD/Lj1L8FEBGxmRI=; b=ZUx6VMBtX576B3Fna5kFb2JBDOhZ8Gr+oI763jXu3YUd3JI8Ta6mc30XevdlebqvTW +uGxif+hJw58tuOimALHH8g/CP70vztlsv/EX6W2lh4rUhwNn2uR50NnbSdXg2fE+q8Y 9oUfPFfEvhpQl0fGs0whlJoTArLH3I8HaHanaWr9ZckXRVCPE2QrA2NItW5orYiJ0Syz GyepVDuAaff526YV0hmxHtHryprtMZwe4QTaHdQP3Ewx1Bxe4OIb8NI2mQ4NngXA3Y1N MFfZc1ZdiRkshhtqrWI3r5HOF3+JuYgsm/KjQyc2zcCYLl8kJGNlzq+N27JsIRTtlUb6 +2qg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d3-v6si16318490pgc.323.2018.05.24.02.06.00; Thu, 24 May 2018 02:06:15 -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; 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 S965810AbeEXJFB (ORCPT + 99 others); Thu, 24 May 2018 05:05:01 -0400 Received: from lb2-smtp-cloud9.xs4all.net ([194.109.24.26]:60476 "EHLO lb2-smtp-cloud9.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965798AbeEXJE4 (ORCPT ); Thu, 24 May 2018 05:04:56 -0400 Received: from [IPv6:2001:983:e9a7:1:a953:cf09:6a9:3f5] ([IPv6:2001:983:e9a7:1:a953:cf09:6a9:3f5]) by smtp-cloud9.xs4all.net with ESMTPA id LmB3for2nRSWtLmB4fMLiH; Thu, 24 May 2018 11:04:55 +0200 Subject: Re: [PATCH v5 1/6] 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, eballetbo@gmail.com References: <1527152101-17278-1-git-send-email-narmstrong@baylibre.com> <1527152101-17278-2-git-send-email-narmstrong@baylibre.com> From: Hans Verkuil Message-ID: Date: Thu, 24 May 2018 11:04:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1527152101-17278-2-git-send-email-narmstrong@baylibre.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfPa2afgOozK8NZJGi2/Pno9j7HU3Ov45haHQhiXR0aF5s7QFXd/KH24GbXNmfdR/xJbAT1dj7CEWTGDVYRBADE2A03PW3BoJuwX5bW1PmLT1p3pg9VKP NTec9jjOJhR9oWIJYPt9NKQTas5GXq4llibRuySoz/0zUCL8PmeKZRIZd24IRkLCljWcXCmgVDCMJYc05a0s4FKWDbTXtwQsdvqanHf7BgrL3DWlug78VkWX mv4E2fDMTQ67w/1RUluB4KTcqSkIS7MVl8lfGdSZCKna7lE+jhWxYL28ARYpWZvlVx0za6SZPFGMUERwwlGYWEwa93Dx7NO+a87DpNzyy3once52HvV9R2Jk 71chY9tO5NNjXxPDEYw/QGWrWjTmfXvSpJ7RaxVaHpMmEtdruLqmSBho58I0F5ux3XEEuEG2559M9smXuTftwjOZkFIpcbfUac5uJDmytAfxwuEN9rDGyTyE ck1A9bEEGY0U6a3oYdUnYpS7fBeBW3+IR0PNEWRUsq/NTZddAhtfD+FOD+oLv1NlXQMVHf3RQ9CBorsc3BL5pX1/nuluB0jflMfZ/clIZMJLVRN+PKKIE1SK cy0lk3/Y8wTjdwDHuWAX3QJU0ZeCh2PAJl3Dg66gpsYS8Ie9mt+Wg1XLFl9K+JN6FPW72AOQ6mA7GQMYwIc5FCxOPXaxFxEJlKvb/JnnHDG95atfFhZFaSru 3+NqPcZCdP9K6s7InETM0DQRJh4kj930hk3EQHdj6J6jPFRO/tUIHNLLterSnNeYD0pvVvCBksHVVCRDvYZMqosAQj0M3DVrQolh0wdwBh4uOlfTC2KOhIBV MUqDvZdVQz8kVQtJI0s= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/05/18 10:54, 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 Reviewed-by: Hans Verkuil Regards, Hans > --- > 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 > * > * 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. > + * > + * 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 >