Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp233020imm; Tue, 15 May 2018 00:29:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq/6dyW+YUO2iPZqCDK1zwlCmqSBmpUKzChdOd4Ee75aS5Wb2PJ+1DVlIaqe/MfHxA2B614 X-Received: by 2002:a63:2547:: with SMTP id l68-v6mr11610351pgl.40.1526369386877; Tue, 15 May 2018 00:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526369386; cv=none; d=google.com; s=arc-20160816; b=se1VKTgK80iFF7dsHMOKDodyX3zgKBSN+HKWNmP0T4X9XBPCbbuVLfLCfRXeFa5d39 MSVtwD2i46Wlq+i4J82Qj2uJ9brkw4g2VQmqjfuvxQlifZbIpJb2+Toa6HW6QKgTrRGx A0xnhH0HfAvBEdhWBzFOSlBCR8NzHirTF36xtpeGI14KI1OpargkpDUAgtLUgYuArfgA l7Q7fL1Pv6sNJxH5aNKo0Uv9bymaBNxKFsrH80ef6kj7L5QnJ+WUzqItR/nvJ5XToxTv FYfB662o6O1qGfd0F+GiorVUanRjHfnlJggLKWCyaVjkl0+kJaCB5TjmiloUq1Gr0vNL qcZA== 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:organization:autocrypt:openpgp:from:references:cc:to :subject:dkim-signature:arc-authentication-results; bh=rmBCZJj7qD59UYdEQ1RXbTXcGhjVeWfD67txcA6w4Do=; b=Bzw1m1rSas3bBoPh0p3FkTJm8qRkaMCtkc018jq58vLLmIQThbB970N7A0XjefcFHb Ay8w7dwWrAuu17Bzhti5FFvPfijzfYdN8/29odrGxdYoPGC6SksWHbL+jr4nJxxjheHQ gawg8NG9FO+bnH1xveK0lNeYbMFzRU+qtJFWbZv0QyhgoGQQaulasr6MGc5sTkJ5eJor N7DoARYVpE0KjqbJeqjrElsy6R7cdJ3RGUZjjD6xYDr5fv5PsoOVo5BlUUD0o2gYeTOn VwPr9zFcvtGNwlazTMc4cfv3xJc5lxe+F3UyLOF6pdLScf4uqTkThcZnX9fZvcp9b9U7 hloQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=Cw0OT04r; 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 u6-v6si11357823pls.462.2018.05.15.00.29.32; Tue, 15 May 2018 00:29:46 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=Cw0OT04r; 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 S1752452AbeEOH26 (ORCPT + 99 others); Tue, 15 May 2018 03:28:58 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:45221 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752433AbeEOH2z (ORCPT ); Tue, 15 May 2018 03:28:55 -0400 Received: by mail-lf0-f67.google.com with SMTP id w202-v6so1044171lff.12 for ; Tue, 15 May 2018 00:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:openpgp:autocrypt:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=rmBCZJj7qD59UYdEQ1RXbTXcGhjVeWfD67txcA6w4Do=; b=Cw0OT04rXahGqxDXZingV7iL8vns//OBW3/MNeAgSr61d5ImbByRnUgpdDUGGnBiq4 S44qtSO/p0P7FM+yTS4zkHDUSl5i86qdce70mnOpXFn8RoMaD5fWpagyp7CIq41/41LW PG+Q4x2ODAxen3Ibrd1uohjvng08dvBZsugzEdUSe66Iim/No5fyiBN3vCJe+aMEC1cj 0JjtEmrZR1CeFtFDJa5PQXAcxwgLFlgMpR1e66m9TEi/Q1lTZy2ND6An5LkFQKCGsjTV +VLkjajy1SEa8qJao1eiONMLyrj0QuLMyWqM1uETN2FH4DdAOHXe8+NOx/bt/I1ncnTV 7s3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=rmBCZJj7qD59UYdEQ1RXbTXcGhjVeWfD67txcA6w4Do=; b=fgjtrjxgsECoHAforbCecAGJrCFAAgUdQ455EEqBDnIczhnqs1R4/vLC2bpnGPxJG+ Lad71KgK/P7LUEKX3vZDWpxG2iJBmdvMJuVGTDQtgPGgeqEDiwx1hTBXY9cmrFafhvx2 kcpnF37l5d44+juZFTHgGh76OXKL8TkSJ1okFxMcuWG+G6PvVuyVaIa9AfB+ShmqJce5 L1bavbWmMXQLX0ZDUI69mY+P/8l6Ymv3aTZ2vhQuTPIAiv6UmrgM3enMPCqB216USU02 UMKlePu188AG9dSwCIpOfpMjsz2L81Vi2D8IkYnWglxSyrRqQ4MMuE38/6rtHxKayC5z EKrQ== X-Gm-Message-State: ALKqPwf8RLqmGPTVuu8WyOFB4pt15HZmiIqhhuURn3+8v17KkYgEVpVa ZedxIbrUeiDhRAE6xIG1KAtnUcLTQoA= X-Received: by 2002:a2e:80c1:: with SMTP id r1-v6mr6703949ljg.85.1526369332915; Tue, 15 May 2018 00:28:52 -0700 (PDT) Received: from ?IPv6:2620:0:1043:fd00:748b:2433:2688:e1f? ([2620:0:1043:fd00:748b:2433:2688:e1f]) by smtp.gmail.com with ESMTPSA id w63-v6sm2894502lfk.0.2018.05.15.00.28.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 00:28:52 -0700 (PDT) Subject: Re: [RFC PATCH 2/5] media: cec-notifier: Get notifier by device and connector name To: Hans Verkuil , 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: <1526337639-3568-1-git-send-email-narmstrong@baylibre.com> <1526337639-3568-3-git-send-email-narmstrong@baylibre.com> From: Neil Armstrong Openpgp: preference=signencrypt Autocrypt: addr=narmstrong@baylibre.com; prefer-encrypt=mutual; keydata= xsBNBE1ZBs8BCAD78xVLsXPwV/2qQx2FaO/7mhWL0Qodw8UcQJnkrWmgTFRobtTWxuRx8WWP GTjuhvbleoQ5Cxjr+v+1ARGCH46MxFP5DwauzPekwJUD5QKZlaw/bURTLmS2id5wWi3lqVH4 BVF2WzvGyyeV1o4RTCYDnZ9VLLylJ9bneEaIs/7cjCEbipGGFlfIML3sfqnIvMAxIMZrvcl9 qPV2k+KQ7q+aXavU5W+yLNn7QtXUB530Zlk/d2ETgzQ5FLYYnUDAaRl+8JUTjc0CNOTpCeik 80TZcE6f8M76Xa6yU8VcNko94Ck7iB4vj70q76P/J7kt98hklrr85/3NU3oti3nrIHmHABEB AAHNKE5laWwgQXJtc3Ryb25nIDxuYXJtc3Ryb25nQGJheWxpYnJlLmNvbT7CwHsEEwEKACUC GyMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheABQJXDO2CAhkBAAoJEBaat7Gkz/iubGIH/iyk RqvgB62oKOFlgOTYCMkYp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p6h8g Organization: Baylibre Message-ID: <9a20dfa6-d61a-637a-0311-e260e555f86f@baylibre.com> Date: Tue, 15 May 2018 09:28:51 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/05/2018 08:27, Hans Verkuil wrote: > Hi Neil, > > Thanks for this patch series! > > Some comments below: > > On 05/15/2018 12:40 AM, 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 | 30 ++++++++++++++++++++++++--- >> include/media/cec-notifier.h | 44 ++++++++++++++++++++++++++++++++++++++-- >> 2 files changed, 69 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c >> index 16dffa0..716070a 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,34 @@ 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_byname(const char *name, >> + 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 (!strcmp(dev_name(n->dev), name) && >> + (!conn || !strcmp(n->conn, conn))) { >> + kref_get(&n->kref); >> + mutex_unlock(&cec_notifiers_lock); >> + return n; >> + } >> + } >> + mutex_unlock(&cec_notifiers_lock); >> + >> + return NULL; > > This doesn't seem right. For one it doesn't act like the other cec_notifier_get* > functions in that it doesn't make a new notifier if it wasn't found yet in the > list. > > For another, I think this function shouldn't be here at all. How about calling > bus_find_device_by_name(), then use cec_notifier_get_conn()? Yes, it's safer and will keep the original cec_notifier_get() behavior. > >> +} >> +EXPORT_SYMBOL_GPL(cec_notifier_get_byname); >> + >> +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 && >> + (!conn || !strcmp(n->conn, conn))) { >> kref_get(&n->kref); >> mutex_unlock(&cec_notifiers_lock); >> return n; >> @@ -46,6 +68,8 @@ struct cec_notifier *cec_notifier_get(struct device *dev) >> if (!n) >> goto unlock; >> n->dev = dev; >> + if (conn) >> + n->conn = devm_kstrdup(dev, conn, GFP_KERNEL); > > The use of devm_kstrdup worries me. The problem is that when the 'dev' device > is removed, this memory is also automatically freed. But the notifier might > still have a reference through the CEC driver, so you end up with a n->conn > pointer that points to freed memory. > > I think it is better to just use kstrdup and kfree it when the last notifier > reference is released. Ok > >> n->phys_addr = CEC_PHYS_ADDR_INVALID; >> mutex_init(&n->lock); >> kref_init(&n->kref); >> @@ -54,7 +78,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) >> { >> diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h >> index cf0add7..70f2974 100644 >> --- a/include/media/cec-notifier.h >> +++ b/include/media/cec-notifier.h >> @@ -20,6 +20,37 @@ struct cec_notifier; >> #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) >> >> /** >> + * cec_notifier_get_byname - find a cec_notifier for the given device name >> + * and connector tuple. >> + * @name: device name that sends the events. >> + * @conn: the connector name from which the event occurs >> + * >> + * If a notifier for device @name exists, then increase the refcount and >> + * return that notifier. >> + * >> + * If it doesn't exist, return NULL >> + */ >> +struct cec_notifier *cec_notifier_get_byname(const char *name, >> + const char *conn); >> + >> +/** >> + * 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 +62,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 +119,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); >> +} >> + >> static inline void cec_notifier_put(struct cec_notifier *n) >> { >> } >> > > Regards, > > Hans >