Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp879115pxk; Thu, 17 Sep 2020 20:08:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8AbnLP0aVS7Mvv9uZ0YtD1WOax7PCC3PrLRuUzfI0AGWilPc11rfsDqde8VSugcTgL75E X-Received: by 2002:a17:906:a2d9:: with SMTP id by25mr34809773ejb.326.1600398528397; Thu, 17 Sep 2020 20:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398528; cv=none; d=google.com; s=arc-20160816; b=g025YjZOWUP1YGf5LRPEFB+y2mXSBCVJBvL7RcxRNz+GkFELHOKUufbsZas5rsPzUP jdHsJABB9oSLXpXithSyGevyibJrv1+m4GNdvEYBfExNw3rVCRzUpXQx2ey0MM4wOqOj jlExiLQxCmgPbjYV+zskkfVYqBSaQ4Gdpe7ahnY09OhMt91cHQ1fUpSrRBfXBgzJju7S BCQBo3EWWFxUIQ5f0m+CpQoAqkVhxZb4Q/9JogjZpj62W1cDbQ4son9QtZzCdn5UwjKu K5kQXgrftE3SjEWwTHqqUiF/ScFLBYP6lL8/7R1YRm5uR7ag5sVgaIZ0EzR0KAllrfmK YA/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3mT31jfxkAJb1zOEWBsJGgZYmWfEeG65EaOaKTUayeY=; b=nO0v1BeEXc73YTKxog5lAYFbBvvi3ghWMT0z9R3NqlrmCUMA5zcmsJI7H4W5bPkcGU 9V+Ix2CVr7k+ey28CwtdyYsXbQLZXzr94Q+LTJ/e1SrewL53uifqJ987vdsfcUG16Y9e MQtse3YvhsvF4O2SZdbeKAXGzwA0klU4r5A0Rq/59kD28AYIZoLo4c/10OwjT+KE/M3T lTlgzNQorxO7Uc2aMdsb3RzMzzYRkXzqWmPQC74bmFw6/trfndqEEfqcMvhUWky0EvgV KugOcqprIxOVoFnA0u12I9QPmAut9LBixGZopKszMFtIfqIZLGOeQPpUYQwaku0RMWu4 6vng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jwgUFXRl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l25si1193228eje.688.2020.09.17.20.08.25; Thu, 17 Sep 2020 20:08:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jwgUFXRl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730631AbgIRDGT (ORCPT + 99 others); Thu, 17 Sep 2020 23:06:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:51080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727234AbgIRCEG (ORCPT ); Thu, 17 Sep 2020 22:04:06 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AF4732311D; Fri, 18 Sep 2020 02:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394645; bh=oC7XsdB7N/fFEDQ6cJcDJzM1yuyD27kdskxwAbo40qE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jwgUFXRlIlug6Ghk/rkRwVMBrrBMj6pS71mtBw6vnIE1HcGBcm5r0R5FFbFicHJJX NlIqKwG9rFS4aI46Gohlr6X+yf20GGeZScpEoRCEgsS9vbVVEJfYxi+HicN/gFy0Qa OBOCqxUgl0XILopSOr8IZ23sV33dfgUYjMd34k6o= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Aric Cyr , Joshua Aberback , Rodrigo Siqueira , Harry Wentland , Alex Deucher , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.4 143/330] drm/amd/display: dal_ddc_i2c_payloads_create can fail causing panic Date: Thu, 17 Sep 2020 21:58:03 -0400 Message-Id: <20200918020110.2063155-143-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aric Cyr [ Upstream commit 6a6c4a4d459ecacc9013c45dcbf2bc9747fdbdbd ] [Why] Since the i2c payload allocation can fail need to check return codes [How] Clean up i2c payload allocations and check for errors Signed-off-by: Aric Cyr Reviewed-by: Joshua Aberback Acked-by: Rodrigo Siqueira Acked-by: Harry Wentland Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../gpu/drm/amd/display/dc/core/dc_link_ddc.c | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c b/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c index 51991bf26a93c..4c90d68db2307 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_link_ddc.c @@ -126,22 +126,16 @@ struct aux_payloads { struct vector payloads; }; -static struct i2c_payloads *dal_ddc_i2c_payloads_create(struct dc_context *ctx, uint32_t count) +static bool dal_ddc_i2c_payloads_create( + struct dc_context *ctx, + struct i2c_payloads *payloads, + uint32_t count) { - struct i2c_payloads *payloads; - - payloads = kzalloc(sizeof(struct i2c_payloads), GFP_KERNEL); - - if (!payloads) - return NULL; - if (dal_vector_construct( &payloads->payloads, ctx, count, sizeof(struct i2c_payload))) - return payloads; - - kfree(payloads); - return NULL; + return true; + return false; } static struct i2c_payload *dal_ddc_i2c_payloads_get(struct i2c_payloads *p) @@ -154,14 +148,12 @@ static uint32_t dal_ddc_i2c_payloads_get_count(struct i2c_payloads *p) return p->payloads.count; } -static void dal_ddc_i2c_payloads_destroy(struct i2c_payloads **p) +static void dal_ddc_i2c_payloads_destroy(struct i2c_payloads *p) { - if (!p || !*p) + if (!p) return; - dal_vector_destruct(&(*p)->payloads); - kfree(*p); - *p = NULL; + dal_vector_destruct(&p->payloads); } #define DDC_MIN(a, b) (((a) < (b)) ? (a) : (b)) @@ -521,9 +513,13 @@ bool dal_ddc_service_query_ddc_data( uint32_t payloads_num = write_payloads + read_payloads; + if (write_size > EDID_SEGMENT_SIZE || read_size > EDID_SEGMENT_SIZE) return false; + if (!payloads_num) + return false; + /*TODO: len of payload data for i2c and aux is uint8!!!!, * but we want to read 256 over i2c!!!!*/ if (dal_ddc_service_is_in_aux_transaction_mode(ddc)) { @@ -556,23 +552,25 @@ bool dal_ddc_service_query_ddc_data( ret = dc_link_aux_transfer_with_retries(ddc, &read_payload); } else { - struct i2c_payloads *payloads = - dal_ddc_i2c_payloads_create(ddc->ctx, payloads_num); + struct i2c_command command = {0}; + struct i2c_payloads payloads; + + if (!dal_ddc_i2c_payloads_create(ddc->ctx, &payloads, payloads_num)) + return false; - struct i2c_command command = { - .payloads = dal_ddc_i2c_payloads_get(payloads), - .number_of_payloads = 0, - .engine = DDC_I2C_COMMAND_ENGINE, - .speed = ddc->ctx->dc->caps.i2c_speed_in_khz }; + command.payloads = dal_ddc_i2c_payloads_get(&payloads); + command.number_of_payloads = 0; + command.engine = DDC_I2C_COMMAND_ENGINE; + command.speed = ddc->ctx->dc->caps.i2c_speed_in_khz; dal_ddc_i2c_payloads_add( - payloads, address, write_size, write_buf, true); + &payloads, address, write_size, write_buf, true); dal_ddc_i2c_payloads_add( - payloads, address, read_size, read_buf, false); + &payloads, address, read_size, read_buf, false); command.number_of_payloads = - dal_ddc_i2c_payloads_get_count(payloads); + dal_ddc_i2c_payloads_get_count(&payloads); ret = dm_helpers_submit_i2c( ddc->ctx, -- 2.25.1