From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752414AbdDPFbC (ORCPT ); Sun, 16 Apr 2017 01:31:02 -0400 Received: from mail.kmu-office.ch ([178.209.48.109]:52604 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751765AbdDPFbB (ORCPT ); Sun, 16 Apr 2017 01:31:01 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: Sat, 15 Apr 2017 22:30:55 -0700 From: Stefan Agner To: Axel Lin Cc: Lee Jones , Marcel Ziswiler , Mark Brown , Liam Girdwood , linux-kernel@vger.kernel.org Subject: Re: [PATCH RESEND] regulator: rn5t618: Fix out of bounds array access In-Reply-To: References: <20170415145239.28880-1-axel.lin@ingics.com> Message-ID: User-Agent: Roundcube Webmail/1.1.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017-04-15 18:12, Axel Lin wrote: > 2017-04-16 0:53 GMT+08:00 Stefan Agner : >> On 2017-04-15 07:52, Axel Lin wrote: >>> The commit "regulator: rn5t618: Add RN5T567 PMIC support" added >>> RN5T618_DCDC4 to the enum, then RN5T618_REG_NUM is also changed. >>> So for rn5t618, there is out of bounds array access when checking >>> regulators[i].name in the for loop. >> >> I use designated initializers ([RN5T618_##rid] = {..), which guarantee >> that the non initialized elements are zero. The highest element LDORTC2 >> is defined, hence the length of the array should be RN5T618_REG_NUM. > > ok, I missed that. Then current code is fine. > Though the meaing of RN5T618_REG_NUM seems misleading to me as different > variant has differnt number of regulators. Yeah I admit the code is somewhat unobvious as it is now. But it allowed me to add RN5T567 support without changing the existing array and the preprocessor macro. -- Stefan