From patchwork Mon Mar 5 13:51:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10258955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C6E6D60211 for ; Mon, 5 Mar 2018 13:51:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B547C28A46 for ; Mon, 5 Mar 2018 13:51:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA0E028A48; Mon, 5 Mar 2018 13:51:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3096028A46 for ; Mon, 5 Mar 2018 13:51:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D6B006E0FD; Mon, 5 Mar 2018 13:51:44 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from lb1-smtp-cloud7.xs4all.net (lb1-smtp-cloud7.xs4all.net [194.109.24.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2D1D56E115 for ; Mon, 5 Mar 2018 13:51:44 +0000 (UTC) Received: from marune.fritz.box ([80.101.105.217]) by smtp-cloud7.xs4all.net with ESMTPA id sqWhehqUp8U07sqWke2ked; Mon, 05 Mar 2018 14:51:42 +0100 From: Hans Verkuil To: linux-media@vger.kernel.org Subject: [PATCHv2 1/7] cec: add core error injection support Date: Mon, 5 Mar 2018 14:51:33 +0100 Message-Id: <20180305135139.95652-2-hverkuil@xs4all.nl> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180305135139.95652-1-hverkuil@xs4all.nl> References: <20180305135139.95652-1-hverkuil@xs4all.nl> X-CMAE-Envelope: MS4wfP4uE/kXmC5jjPzAuV9prCL6c/gmMOrNyDraVA5xjoXm5+AtLG9tj0LtzfdjTIwnSzsMHPNn1SFH3Wb9vNBkkRzeEqa8YNafkpS5miNTzo0JGqeKgxLa 3DMHpxXtJ5ev625uCFijZdsNZ2a0PZlFbzlYW9tqxyFOcUvE0k3b1zgN+z1UDInO5xhlNLCaZzB+/bVNAXXr6D8N/zjL4YsIKumURrq1gMphjEqATc9wjW6Q gXDVuLag4WjtbBNqv1vxxy+Xn0kXLu2jrPJoqXMI/pScoEeSH0QfL6Z9zCxIneB+VMyDyZsak3vKWfcghpOpoA== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Hans Verkuil , dri-devel@lists.freedesktop.org, Wolfram Sang MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil Add two new ops (error_inj_show and error_inj_parse_line) to support error injection functionality for CEC adapters. If both are present, then the core will add a new error-inj debugfs file that can be used to see the current error injection commands and to set error injection commands. Signed-off-by: Hans Verkuil --- drivers/media/cec/cec-core.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ include/media/cec.h | 5 ++++ 2 files changed, 63 insertions(+) diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c index e47ea22b3c23..ea3eccfdba15 100644 --- a/drivers/media/cec/cec-core.c +++ b/drivers/media/cec/cec-core.c @@ -195,6 +195,55 @@ void cec_register_cec_notifier(struct cec_adapter *adap, EXPORT_SYMBOL_GPL(cec_register_cec_notifier); #endif +#ifdef CONFIG_DEBUG_FS +static ssize_t cec_error_inj_write(struct file *file, + const char __user *ubuf, size_t count, loff_t *ppos) +{ + struct seq_file *sf = file->private_data; + struct cec_adapter *adap = sf->private; + char *buf; + char *line; + char *p; + + buf = memdup_user_nul(ubuf, min_t(size_t, PAGE_SIZE, count)); + if (IS_ERR(buf)) + return PTR_ERR(buf); + p = buf; + while (p && *p && count >= 0) { + p = skip_spaces(p); + line = strsep(&p, "\n"); + if (!*line || *line == '#') + continue; + if (!adap->ops->error_inj_parse_line(adap, line)) { + count = -EINVAL; + break; + } + } + kfree(buf); + return count; +} + +static int cec_error_inj_show(struct seq_file *sf, void *unused) +{ + struct cec_adapter *adap = sf->private; + + return adap->ops->error_inj_show(adap, sf); +} + +static int cec_error_inj_open(struct inode *inode, struct file *file) +{ + return single_open(file, cec_error_inj_show, inode->i_private); +} + +static const struct file_operations cec_error_inj_fops = { + .open = cec_error_inj_open, + .write = cec_error_inj_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +#endif + struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, void *priv, const char *name, u32 caps, u8 available_las) @@ -334,7 +383,16 @@ int cec_register_adapter(struct cec_adapter *adap, pr_warn("cec-%s: Failed to create status file\n", adap->name); debugfs_remove_recursive(adap->cec_dir); adap->cec_dir = NULL; + return 0; } + if (!adap->ops->error_inj_show || !adap->ops->error_inj_parse_line) + return 0; + adap->error_inj_file = debugfs_create_file("error-inj", 0644, + adap->cec_dir, adap, + &cec_error_inj_fops); + if (IS_ERR_OR_NULL(adap->error_inj_file)) + pr_warn("cec-%s: Failed to create error-inj file\n", + adap->name); #endif return 0; } diff --git a/include/media/cec.h b/include/media/cec.h index 9afba9b558df..41df048efc55 100644 --- a/include/media/cec.h +++ b/include/media/cec.h @@ -117,6 +117,10 @@ struct cec_adap_ops { void (*adap_status)(struct cec_adapter *adap, struct seq_file *file); void (*adap_free)(struct cec_adapter *adap); + /* Error injection callbacks */ + int (*error_inj_show)(struct cec_adapter *adap, struct seq_file *sf); + bool (*error_inj_parse_line)(struct cec_adapter *adap, char *line); + /* High-level CEC message callback */ int (*received)(struct cec_adapter *adap, struct cec_msg *msg); }; @@ -189,6 +193,7 @@ struct cec_adapter { struct dentry *cec_dir; struct dentry *status_file; + struct dentry *error_inj_file; u16 phys_addrs[15]; u32 sequence;