From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753071AbeEVUqL (ORCPT ); Tue, 22 May 2018 16:46:11 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:46032 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752764AbeEVUqJ (ORCPT ); Tue, 22 May 2018 16:46:09 -0400 X-Google-Smtp-Source: ADUXVKJU5GOy2FLMOyAzvetqIq+uP5xOtKtDEx8NqxwXDb7O+XFYA72tgsXyd+fDlLNkSwyeolhb7mrz1319rUV5whA= MIME-Version: 1.0 In-Reply-To: <19968f96da0c548dd7d96e7520ce899e@codeaurora.org> References: <1526492623-20527-1-git-send-email-rishabhb@codeaurora.org> <1526492623-20527-3-git-send-email-rishabhb@codeaurora.org> <19968f96da0c548dd7d96e7520ce899e@codeaurora.org> From: Andy Shevchenko Date: Tue, 22 May 2018 23:46:07 +0300 Message-ID: Subject: Re: [PATCH v7 2/2] drivers: soc: Add LLCC driver To: Rishabh Bhatnagar Cc: linux-arm Mailing List , linux-arm-msm@vger.kernel.org, devicetree , Linux Kernel Mailing List , linux-arm@lists.infradead.org, tsoni@codeaurora.org, ckadabi@codeaurora.org, Evan Green , Rob Herring Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 22, 2018 at 11:40 PM, wrote: > On 2018-05-22 12:38, Andy Shevchenko wrote: >> On Tue, May 22, 2018 at 9:33 PM, wrote: >>> On 2018-05-18 14:01, Andy Shevchenko wrote: >>>>> +struct llcc_slice_desc *llcc_slice_getd(u32 uid) >>>>> +{ >>>>> + const struct llcc_slice_config *cfg; >>>>> + struct llcc_slice_desc *desc; >>>>> + u32 sz, count = 0; >>>>> + >>>>> + cfg = drv_data->cfg; >>>>> + sz = drv_data->cfg_size; >>>>> + >>>> >>>> >>>> >>>>> + while (cfg && count < sz) { >>>>> + if (cfg->usecase_id == uid) >>>>> + break; >>>>> + cfg++; >>>>> + count++; >>>>> + } >>>>> + if (cfg == NULL || count == sz) >>>>> + return ERR_PTR(-ENODEV); >>>> if (!cfg) >>>> return ERR_PTR(-ENODEV); >>>> >>>> while (cfg->... != uid) { >>>> cfg++; >>>> count++; >>>> } >>>> >>>> if (count == sz) >>>> return ... >>>> >>>> Though I would rather put it to for () loop. >>>> >>> In each while loop iteration the cfg pointer needs to be checked for >>> NULL. What if the usecase id never matches the uid passed by client >>> and we keep iterating. At some point it will crash. >> do { >> if (!cfg || count == sz) >> return ...(-ENODEV); >> ... >> } while (...); >> >> Though, as I said for-loop will look slightly better I think. > > Is this fine? > for (count = 0; count < sz; count++) { > if (!cfg) > return ERR_PTR(-ENODEV); > if (cfg->usecase_id == uid) > break; > cfg++; > } > if (count == sz) > return ERR_PTR(-ENODEV); for (count = 0; cfg && count < sz; count++, cfg++) if (_id == uid) break; if (!cfg || count == sz) return ERR_PTR(-ENODEV); Simpler ? -- With Best Regards, Andy Shevchenko