From patchwork Sun Aug 28 06:54:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoyou Xie X-Patchwork-Id: 74870 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1087396qga; Sat, 27 Aug 2016 23:55:26 -0700 (PDT) X-Received: by 10.66.155.7 with SMTP id vs7mr20883643pab.154.1472367325954; Sat, 27 Aug 2016 23:55:25 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s126si31726747pfb.16.2016.08.27.23.55.25; Sat, 27 Aug 2016 23:55:25 -0700 (PDT) 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=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932479AbcH1GzX (ORCPT + 27 others); Sun, 28 Aug 2016 02:55:23 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:36421 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932299AbcH1GzW (ORCPT ); Sun, 28 Aug 2016 02:55:22 -0400 Received: by mail-pa0-f53.google.com with SMTP id di2so39530455pad.3 for ; Sat, 27 Aug 2016 23:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=RwjSu6DXElhmpdrePJyMzlsFM3loJgAeLYDXNJG22hI=; b=P0i0/ypls6VcBuISXYxQ4lm0/etYJc2u6Qo7VPHZrHESSJvxLaSaj9kM2C+Ax16ewz YZekYlrIWxVy7WQNW+gpwI6ig5E12lC382bXLae6/P9E8Fjildao4nvf+Gv7GsHdteSa h3Rt/tgPAKXH9kqB/J41twteDHfvHq+GoNEUs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=RwjSu6DXElhmpdrePJyMzlsFM3loJgAeLYDXNJG22hI=; b=MZmmfoAduXcWQiOrsWjT7AZ1LnXJlADTi0ddTGY7MFzNG5RHkRmebOzb/rlT/IE0HA PGvQj/5rper4NRMpu+pHeGFy2oUiAnvjXBjOsGOZtG/fL6WeMFzoDx82UnUpda8Nnctu nz3Wjd3blijVlp/HrjfvWgM/xKIzHDmxJ55GoQKJpfSSvsTqYKvGX0JNXJV2loMJoqRr sdPJkNf2QcsH1AK7NSU8jRGMHBkwZ395va4V9j17nowSgw9eL3ypl18P0wSq7M0P0DWr xLMzvUtTfdeSHvi5PxD6RK9bVFDLw4+Mdc+eDl2L6XUPhvkXm/+srZ+hPsevnyRcJ+c0 Rp2Q== X-Gm-Message-State: AE9vXwOpOc9VKK0H3+5bVBoSoWIH2TLPQQUSrKnG4KfDd1VsVznw3bokY6/KgpNeR0s5ORb3 X-Received: by 10.66.53.234 with SMTP id e10mr21182035pap.28.1472367321329; Sat, 27 Aug 2016 23:55:21 -0700 (PDT) Received: from localhost.localdomain ([104.237.91.142]) by smtp.gmail.com with ESMTPSA id p4sm40003271pfp.60.2016.08.27.23.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 27 Aug 2016 23:55:20 -0700 (PDT) From: Baoyou Xie To: maximlevitsky@gmail.com Cc: linux-kernel@vger.kernel.org, arnd@linaro.org, baoyou.xie@linaro.org, xie.baoyou@zte.com.cn Subject: [PATCH] memstick: r592: add sanity check in r592.c Date: Sun, 28 Aug 2016 14:54:46 +0800 Message-Id: <1472367286-14528-1-git-send-email-baoyou.xie@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org in function memstick_debug_get_tpc_name, it miss sanity check and will cause a panic. so this patch checks if the tpc parameter is valid, and if not so, it returns a dummy value to caller. Signed-off-by: Baoyou Xie --- drivers/memstick/host/r592.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.7.4 diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c index d5cfb50..fc752ae 100644 --- a/drivers/memstick/host/r592.c +++ b/drivers/memstick/host/r592.c @@ -49,6 +49,9 @@ static const char *tpc_names[] = { */ const char *memstick_debug_get_tpc_name(int tpc) { + if (tpc < 1 || tpc > ARRAY_SIZE(tpc_names)) + return ""; + return tpc_names[tpc-1]; } EXPORT_SYMBOL(memstick_debug_get_tpc_name);