Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1132254imm; Fri, 29 Jun 2018 11:59:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe53nLnmzVpClIsmnPc3TATMr1IIDsIh795KQLF/J6M6Oux0/NCPiZANs8Ki7OW9Ofvl29m X-Received: by 2002:aa7:8298:: with SMTP id s24-v6mr15609566pfm.136.1530298753458; Fri, 29 Jun 2018 11:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530298753; cv=none; d=google.com; s=arc-20160816; b=02OdpLeYiaXxFBe5cCT15x3AgfgYtIK5+AzbUGcQVpSqKrZYtjMpbHhsvh2Q6ZRsV0 a/xtjpK1Sdj7/Upz03/4WllxVA7mVSxG/j4PJz2mCvqQDlqIOVGDCMNy7BchZ2Sd4UNq +2YPujxhtWiEuCjS206GKPJ1z6nizSGQ2YaM1/BFA6v3bhYCc+Dv++hlngiyTuIoO0Yl JRpndxdHgPrqQHpADxl1w/YcjfQJXqj4jqSHcp34jh4pB/tH0ZdwsOxly1zu5P5MS45q FB1/VKzRlF7ll0C0B/6bcKhNNutGtogoRumgMnLud0fvQScqb/zZ0Xrlvv9TanuJ5Kfz CRow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=lE+v0pt0qUxtsD563AOlvgJb3eTiEqGz7kyGQ3Z0e4Q=; b=ZUhUe3JvhtIyA1yEb1opCPADwAQfjomfFVCigSj8yrHXCv8T/yrYaH5J2JB1xOIvgX xkUn20QCKMsa/ma5V4PTbxPfLYWXnTaaB5eI1dQ8EAC4FeoIzfAzAKbNEOUuYBTsEz8L xBATsRLDV8GWXw7OR1lVmvqY62nM9Qm0bExtgozozzoGLxq+TXk2mwXmbynwn6DnbxRj 2oaMoIZem5RJNRqF0bi2IiNYt+llMli25kZvnpvHMDJ4cddr/cViN9qCi9lFtAEbObM/ 2Ch/VfjW37KohYDMquBr/JIqzbwzeORmrayk6huKvC0BSZGK4rO2x1zKFZ/AeRoGCoP9 Wnug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CyD2OGT2; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g26-v6si9871666pfe.4.2018.06.29.11.58.59; Fri, 29 Jun 2018 11:59:13 -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=@gmail.com header.s=20161025 header.b=CyD2OGT2; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936649AbeF2Suz (ORCPT + 99 others); Fri, 29 Jun 2018 14:50:55 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:37338 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933582AbeF2Suu (ORCPT ); Fri, 29 Jun 2018 14:50:50 -0400 Received: by mail-pl0-f65.google.com with SMTP id 31-v6so4869843plc.4; Fri, 29 Jun 2018 11:50:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lE+v0pt0qUxtsD563AOlvgJb3eTiEqGz7kyGQ3Z0e4Q=; b=CyD2OGT2V5aS/+v5rI8ZWM7tvQdVA1mmj729OfHFdeBGJOXZm7RZ5UFGrLVuELKCBR OS3NDct07rKjvSuscNo7exFKc0gB2+2RZPHwL1wVzQhqUllhgskzx0o0fXJ5EVPnvZnR tKIOrK9D4HugMm40FTB9a/YhXvWjlwsKllU9LjOrAd6jHHU7apnxuQlNIlRFfroWXUHM 4cW5gg6iuDPBCPuNRFK8mKWG8TNJ+4Miic3qz4RRSPs0oCtIH4HnSnktkFQPKAlfj7m0 NXUPxnpxkAINxA+D/NosBP81AkF3iZWEyyG+HXxG0Yq5hfzPidsm7yrTdmQpGMXDbRAF OYKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lE+v0pt0qUxtsD563AOlvgJb3eTiEqGz7kyGQ3Z0e4Q=; b=HnSMqt9+Nd3iy0xB/4ZuuiN5SUsJHVdO8A29pYM1IA4WexvIVaimTRipytC9Mtgbf1 i8rNesScZqmBzQUENoeiZGsD9h7dkNtlpu23bl7AmJ9ml7uDtmd5csoFNNZF0lzJpNWt jtl5UKksWUKK8iedE4VpXK89iE4SlbTpxx5XlEvu8wv/GJzoqv4Nx9OUwNlK0Q8rHEXo rQKP3fBAY1N9OUs0R1+XlX9DQYXhD3PzBEiV9IDesTmLCA4sjbJDO+lxJs89AO5f1eIJ jviDMHT0BkS1dbvKu5/8B4d28KZ2vylUcqOljnvKLtVvottEtrLcEfcxcCdKDG/qZ9B7 JgFw== X-Gm-Message-State: APt69E0TlmHMPq4yQW2pFY6Ra2OGMKkEsGwmXA7bdkyfPTZoSBz9lgcZ 845e0+guZjs4KA2gek7uvavreg== X-Received: by 2002:a17:902:ba8a:: with SMTP id k10-v6mr16081744pls.338.1530298249351; Fri, 29 Jun 2018 11:50:49 -0700 (PDT) Received: from mappy.world.mentorg.com ([2602:306:cc3b:f020:7cd8:9ad7:a375:e853]) by smtp.googlemail.com with ESMTPSA id k13-v6sm27672308pfg.130.2018.06.29.11.50.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jun 2018 11:50:48 -0700 (PDT) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , linux-kernel@vger.kernel.org Subject: [PATCH v5 02/17] media: v4l2: async: Allow searching for asd of any type Date: Fri, 29 Jun 2018 11:49:46 -0700 Message-Id: <1530298220-5097-3-git-send-email-steve_longerbeam@mentor.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530298220-5097-1-git-send-email-steve_longerbeam@mentor.com> References: <1530298220-5097-1-git-send-email-steve_longerbeam@mentor.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Generalize v4l2_async_notifier_fwnode_has_async_subdev() to allow searching for any type of async subdev, not just fwnodes. Rename to v4l2_async_notifier_has_async_subdev() and pass it an asd pointer. Signed-off-by: Steve Longerbeam --- Changes since v4: - none Changes since v3: - removed TODO to support asd compare with CUSTOM match type in asd_equal(). Changes since v2: - code optimization in asd_equal(), and remove unneeded braces, suggested by Sakari Ailus. Changes since v1: - none --- drivers/media/v4l2-core/v4l2-async.c | 73 +++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 2b08d03..0e7e529 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -124,6 +124,31 @@ static struct v4l2_async_subdev *v4l2_async_find_match( return NULL; } +/* Compare two asd's for equivalence */ +static bool asd_equal(struct v4l2_async_subdev *asd_x, + struct v4l2_async_subdev *asd_y) +{ + if (asd_x->match_type != asd_y->match_type) + return false; + + switch (asd_x->match_type) { + case V4L2_ASYNC_MATCH_DEVNAME: + return strcmp(asd_x->match.device_name, + asd_y->match.device_name) == 0; + case V4L2_ASYNC_MATCH_I2C: + return asd_x->match.i2c.adapter_id == + asd_y->match.i2c.adapter_id && + asd_x->match.i2c.address == + asd_y->match.i2c.address; + case V4L2_ASYNC_MATCH_FWNODE: + return asd_x->match.fwnode == asd_y->match.fwnode; + default: + break; + } + + return false; +} + /* Find the sub-device notifier registered by a sub-device driver. */ static struct v4l2_async_notifier *v4l2_async_find_subdev_notifier( struct v4l2_subdev *sd) @@ -308,29 +333,22 @@ static void v4l2_async_notifier_unbind_all_subdevs( notifier->parent = NULL; } -/* See if an fwnode can be found in a notifier's lists. */ -static bool __v4l2_async_notifier_fwnode_has_async_subdev( - struct v4l2_async_notifier *notifier, struct fwnode_handle *fwnode) +/* See if an async sub-device can be found in a notifier's lists. */ +static bool __v4l2_async_notifier_has_async_subdev( + struct v4l2_async_notifier *notifier, struct v4l2_async_subdev *asd) { - struct v4l2_async_subdev *asd; + struct v4l2_async_subdev *asd_y; struct v4l2_subdev *sd; - list_for_each_entry(asd, ¬ifier->waiting, list) { - if (asd->match_type != V4L2_ASYNC_MATCH_FWNODE) - continue; - - if (asd->match.fwnode == fwnode) + list_for_each_entry(asd_y, ¬ifier->waiting, list) + if (asd_equal(asd, asd_y)) return true; - } list_for_each_entry(sd, ¬ifier->done, async_list) { if (WARN_ON(!sd->asd)) continue; - if (sd->asd->match_type != V4L2_ASYNC_MATCH_FWNODE) - continue; - - if (sd->asd->match.fwnode == fwnode) + if (asd_equal(asd, sd->asd)) return true; } @@ -338,32 +356,28 @@ static bool __v4l2_async_notifier_fwnode_has_async_subdev( } /* - * Find out whether an async sub-device was set up for an fwnode already or + * Find out whether an async sub-device was set up already or * whether it exists in a given notifier before @this_index. */ -static bool v4l2_async_notifier_fwnode_has_async_subdev( - struct v4l2_async_notifier *notifier, struct fwnode_handle *fwnode, +static bool v4l2_async_notifier_has_async_subdev( + struct v4l2_async_notifier *notifier, struct v4l2_async_subdev *asd, unsigned int this_index) { unsigned int j; lockdep_assert_held(&list_lock); - /* Check that an fwnode is not being added more than once. */ + /* Check that an asd is not being added more than once. */ for (j = 0; j < this_index; j++) { - struct v4l2_async_subdev *asd = notifier->subdevs[this_index]; - struct v4l2_async_subdev *other_asd = notifier->subdevs[j]; + struct v4l2_async_subdev *asd_y = notifier->subdevs[j]; - if (other_asd->match_type == V4L2_ASYNC_MATCH_FWNODE && - asd->match.fwnode == - other_asd->match.fwnode) + if (asd_equal(asd, asd_y)) return true; } - /* Check than an fwnode did not exist in other notifiers. */ + /* Check that an asd does not exist in other notifiers. */ list_for_each_entry(notifier, ¬ifier_list, list) - if (__v4l2_async_notifier_fwnode_has_async_subdev( - notifier, fwnode)) + if (__v4l2_async_notifier_has_async_subdev(notifier, asd)) return true; return false; @@ -392,12 +406,11 @@ static int __v4l2_async_notifier_register(struct v4l2_async_notifier *notifier) case V4L2_ASYNC_MATCH_CUSTOM: case V4L2_ASYNC_MATCH_DEVNAME: case V4L2_ASYNC_MATCH_I2C: - break; case V4L2_ASYNC_MATCH_FWNODE: - if (v4l2_async_notifier_fwnode_has_async_subdev( - notifier, asd->match.fwnode, i)) { + if (v4l2_async_notifier_has_async_subdev( + notifier, asd, i)) { dev_err(dev, - "fwnode has already been registered or in notifier's subdev list\n"); + "asd has already been registered or in notifier's subdev list\n"); ret = -EEXIST; goto err_unlock; } -- 2.7.4