From patchwork Wed Jun 7 09:52:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 9771169 X-Patchwork-Delegate: geert@linux-m68k.org 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 9DFEE6034B for ; Wed, 7 Jun 2017 09:55:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E449284C5 for ; Wed, 7 Jun 2017 09:55:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 732C9284D2; Wed, 7 Jun 2017 09:55:26 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F03F3284CF for ; Wed, 7 Jun 2017 09:55:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751476AbdFGJww (ORCPT ); Wed, 7 Jun 2017 05:52:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:45494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751464AbdFGJwM (ORCPT ); Wed, 7 Jun 2017 05:52:12 -0400 Received: from CookieMonster.cookiemonster.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CE929239AC; Wed, 7 Jun 2017 09:52:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE929239AC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=kbingham@kernel.org From: Kieran Bingham To: sakari.ailus@iki.fi, linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, niklas.soderlund@ragnatech.se, linux-renesas-soc@vger.kernel.org, kieran.bingham@ideasonboard.com, Kieran Bingham Subject: [PATCH v4] v4l: subdev: tolerate null in media_entity_to_v4l2_subdev Date: Wed, 7 Jun 2017 10:52:07 +0100 Message-Id: <1496829127-28375-1-git-send-email-kbingham@kernel.org> X-Mailer: git-send-email 2.7.4 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kieran Bingham Return NULL, if a null entity is parsed for it's v4l2_subdev Signed-off-by: Kieran Bingham Reviewed-by: Sakari Ailus --- Not sure if this patch ever made it out of my mailbox: Here's the respin with the parameter evaluated only once. v4: - Improve macro usage to evaluate ent only once include/media/v4l2-subdev.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index a40760174797..0f92ebd2d710 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -826,8 +826,15 @@ struct v4l2_subdev { struct v4l2_subdev_platform_data *pdata; }; -#define media_entity_to_v4l2_subdev(ent) \ - container_of(ent, struct v4l2_subdev, entity) +#define media_entity_to_v4l2_subdev(ent) \ +({ \ + typeof(ent) __me_sd_ent = (ent); \ + \ + __me_sd_ent ? \ + container_of(__me_sd_ent, struct v4l2_subdev, entity) : \ + NULL; \ +}) + #define vdev_to_v4l2_subdev(vdev) \ ((struct v4l2_subdev *)video_get_drvdata(vdev))