Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3472102imu; Sun, 11 Nov 2018 15:53:40 -0800 (PST) X-Google-Smtp-Source: AJdET5eummgKrdaaZCFt7o5LoDfSKPIrbHAbOXfeYih1V0Hj4/2OznTm6uV/MaScUwZGWEBiydSX X-Received: by 2002:a62:3346:: with SMTP id z67-v6mr9782225pfz.112.1541980420814; Sun, 11 Nov 2018 15:53:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980420; cv=none; d=google.com; s=arc-20160816; b=dhWxei/3NtVDYxpvBlQdf5WeRUEFgx26K489a6NYfs0Y/KBsCfoDq0QRNgOu60HUlW yra7SDQeyAhXB54xh6oybV+vuSeiZTMuf+fbCfCTMYdBEv7ixEFwBWIVitc53drHRnmN sEL4HJENiLRuLIIon62yTVhQrh4EAngd92RxEJxTDfP8Pphmmx5hNlhRBREYOoprTiKz 6ln3mNdMxMsihzjbUvObKB3PZSMcByM5G5AfwKha9o0AjugwTFde89fv5dnc+9PjgKc/ eOQS7AihvZIOFPgpFV5Y7YHE/SE2aTSeSZ7t0AuOLr1inoaWC6b88VR29fw8ZgU0G8hu VzJg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6yagmMV0rFTykduiG39sq7Sglp3YDzxtBRSbdg1BroM=; b=kGW3l5vWynAalwUxKjkrjvap4xOqEFPjcWDjTFlA4c2SJCDu+k4rZFnJMLEhicc03b NY4/fGp92sJaMk3qCaExG4rz6X3j9T8Mpm0+Dr2i1MwTFuBn7OxBqUfxrpbevTWt5BOx FWhMnXVymb4pCyqxea4aCJPx0ordH4xsMPaIZEr242Wvw8IENHCKxhnPLe3FYvEpYYLu LRtWevqkSafHCdemv5c6A03sM0e+dRuWg47mArlSj144Wzbx/Et+2pRAQO8Aok2w9HQm HgSIE3ipdnsDBcCFiZhNgRgG8Rb/BDuHW7gZN/nQXoxIXp8cpvFdM9dh4wqFNCtEiv+d ij0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=idnWWZFh; 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 u128-v6si18300550pfc.145.2018.11.11.15.53.25; Sun, 11 Nov 2018 15:53:40 -0800 (PST) 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=@kernel.org header.s=default header.b=idnWWZFh; 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 S1732854AbeKLISa (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:37584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732829AbeKLIS3 (ORCPT ); Mon, 12 Nov 2018 03:18:29 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A96E223C6; Sun, 11 Nov 2018 22:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975313; bh=dJWBRphxZntlzYvmDmOy3G+5oNn7fbhqbgpbiAdKWuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=idnWWZFhou/JL9OBK7TX4KjfNDAaP8ZXfWGeQYV0Gk325m3mQ228eOFl29rxXZ4pu OZS3Z0r2GGDns180z+hUmRH4wuJAUIYTKPfY6lPdlwgYTCVmyoZbaYWtOgFVdYOQrg I8EUD64oBgz4eyhSeG6f1jMjERUl8+5xIsT+1Wds= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab Subject: [PATCH 4.19 297/361] media: cec: make cec_get_edid_spa_location() an inline function Date: Sun, 11 Nov 2018 14:20:44 -0800 Message-Id: <20181111221657.178750719@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hans Verkuil commit b915bf575d5b7774d0f22d57d6c143e07dcaade2 upstream. This function is needed by both V4L2 and CEC, so move this to cec.h as a static inline since there are no obvious shared modules between the two subsystems. This patch, together with the following ones, fixes a dependency bug: if CEC_CORE is disabled, then building adv7604 (and other HDMI receivers) will fail because an essential function is now stubbed out. Signed-off-by: Hans Verkuil Cc: # for v4.17 and up Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/cec/cec-edid.c | 60 ------------------------------------ include/media/cec.h | 70 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 60 deletions(-) --- a/drivers/media/cec/cec-edid.c +++ b/drivers/media/cec/cec-edid.c @@ -10,66 +10,6 @@ #include #include -/* - * This EDID is expected to be a CEA-861 compliant, which means that there are - * at least two blocks and one or more of the extensions blocks are CEA-861 - * blocks. - * - * The returned location is guaranteed to be < size - 1. - */ -static unsigned int cec_get_edid_spa_location(const u8 *edid, unsigned int size) -{ - unsigned int blocks = size / 128; - unsigned int block; - u8 d; - - /* Sanity check: at least 2 blocks and a multiple of the block size */ - if (blocks < 2 || size % 128) - return 0; - - /* - * If there are fewer extension blocks than the size, then update - * 'blocks'. It is allowed to have more extension blocks than the size, - * since some hardware can only read e.g. 256 bytes of the EDID, even - * though more blocks are present. The first CEA-861 extension block - * should normally be in block 1 anyway. - */ - if (edid[0x7e] + 1 < blocks) - blocks = edid[0x7e] + 1; - - for (block = 1; block < blocks; block++) { - unsigned int offset = block * 128; - - /* Skip any non-CEA-861 extension blocks */ - if (edid[offset] != 0x02 || edid[offset + 1] != 0x03) - continue; - - /* search Vendor Specific Data Block (tag 3) */ - d = edid[offset + 2] & 0x7f; - /* Check if there are Data Blocks */ - if (d <= 4) - continue; - if (d > 4) { - unsigned int i = offset + 4; - unsigned int end = offset + d; - - /* Note: 'end' is always < 'size' */ - do { - u8 tag = edid[i] >> 5; - u8 len = edid[i] & 0x1f; - - if (tag == 3 && len >= 5 && i + len <= end && - edid[i + 1] == 0x03 && - edid[i + 2] == 0x0c && - edid[i + 3] == 0x00) - return i + 4; - i += len + 1; - } while (i < end); - } - } - return 0; -} - u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size, unsigned int *offset) { --- a/include/media/cec.h +++ b/include/media/cec.h @@ -461,4 +461,74 @@ static inline void cec_phys_addr_invalid cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false); } +/** + * cec_get_edid_spa_location() - find location of the Source Physical Address + * + * @edid: the EDID + * @size: the size of the EDID + * + * This EDID is expected to be a CEA-861 compliant, which means that there are + * at least two blocks and one or more of the extensions blocks are CEA-861 + * blocks. + * + * The returned location is guaranteed to be <= size-2. + * + * This is an inline function since it is used by both CEC and V4L2. + * Ideally this would go in a module shared by both, but it is overkill to do + * that for just a single function. + */ +static inline unsigned int cec_get_edid_spa_location(const u8 *edid, + unsigned int size) +{ + unsigned int blocks = size / 128; + unsigned int block; + u8 d; + + /* Sanity check: at least 2 blocks and a multiple of the block size */ + if (blocks < 2 || size % 128) + return 0; + + /* + * If there are fewer extension blocks than the size, then update + * 'blocks'. It is allowed to have more extension blocks than the size, + * since some hardware can only read e.g. 256 bytes of the EDID, even + * though more blocks are present. The first CEA-861 extension block + * should normally be in block 1 anyway. + */ + if (edid[0x7e] + 1 < blocks) + blocks = edid[0x7e] + 1; + + for (block = 1; block < blocks; block++) { + unsigned int offset = block * 128; + + /* Skip any non-CEA-861 extension blocks */ + if (edid[offset] != 0x02 || edid[offset + 1] != 0x03) + continue; + + /* search Vendor Specific Data Block (tag 3) */ + d = edid[offset + 2] & 0x7f; + /* Check if there are Data Blocks */ + if (d <= 4) + continue; + if (d > 4) { + unsigned int i = offset + 4; + unsigned int end = offset + d; + + /* Note: 'end' is always < 'size' */ + do { + u8 tag = edid[i] >> 5; + u8 len = edid[i] & 0x1f; + + if (tag == 3 && len >= 5 && i + len <= end && + edid[i + 1] == 0x03 && + edid[i + 2] == 0x0c && + edid[i + 3] == 0x00) + return i + 4; + i += len + 1; + } while (i < end); + } + } + return 0; +} + #endif /* _MEDIA_CEC_H */