From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E50E0C0650F for ; Tue, 6 Aug 2019 00:55:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3D9D2070D for ; Tue, 6 Aug 2019 00:55:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731203AbfHFAzb (ORCPT ); Mon, 5 Aug 2019 20:55:31 -0400 Received: from mga07.intel.com ([134.134.136.100]:35775 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729383AbfHFAz3 (ORCPT ); Mon, 5 Aug 2019 20:55:29 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Aug 2019 17:55:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,350,1559545200"; d="scan'208";a="198153105" Received: from sahluwal-mobl1.amr.corp.intel.com (HELO pbossart-mobl3.intel.com) ([10.252.202.215]) by fmsmga004.fm.intel.com with ESMTP; 05 Aug 2019 17:55:28 -0700 From: Pierre-Louis Bossart To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, tiwai@suse.de, broonie@kernel.org, vkoul@kernel.org, gregkh@linuxfoundation.org, jank@cadence.com, srinivas.kandagatla@linaro.org, Blauciak@vger.kernel.org, Slawomir , Pierre-Louis Bossart , Sanyog Kale Subject: [PATCH 01/17] soundwire: intel: prevent possible dereference in hw_params Date: Mon, 5 Aug 2019 19:55:06 -0500 Message-Id: <20190806005522.22642-2-pierre-louis.bossart@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190806005522.22642-1-pierre-louis.bossart@linux.intel.com> References: <20190806005522.22642-1-pierre-louis.bossart@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This should not happen in production systems but we should test for all callback arguments before invoking the config_stream callback. Update the prototype to clarify that the first argument is mandatory. Also use local variable instead of multiple dereferences to improve readability. Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/intel.c | 6 ++++-- include/linux/soundwire/sdw_intel.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index 3d9ca6479e94..a906789c7f78 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -498,8 +498,10 @@ static int intel_config_stream(struct sdw_intel *sdw, struct snd_soc_dai *dai, struct snd_pcm_hw_params *hw_params, int link_id) { - if (sdw->res->ops && sdw->res->ops->config_stream) - return sdw->res->ops->config_stream(sdw->res->arg, + struct sdw_intel_link_res *res = sdw->res; + + if (res->ops && res->ops->config_stream && res->arg) + return res->ops->config_stream(res->arg, substream, dai, hw_params, link_id); return -EIO; diff --git a/include/linux/soundwire/sdw_intel.h b/include/linux/soundwire/sdw_intel.h index 4d70da45363d..c9427cb6020b 100644 --- a/include/linux/soundwire/sdw_intel.h +++ b/include/linux/soundwire/sdw_intel.h @@ -8,6 +8,7 @@ * struct sdw_intel_ops: Intel audio driver callback ops * * @config_stream: configure the stream with the hw_params + * the first argument containing the context is mandatory */ struct sdw_intel_ops { int (*config_stream)(void *arg, void *substream, -- 2.20.1