Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp48744imm; Tue, 22 May 2018 13:47:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpayiGMP2diW91gl6jjY1TVQN8kHNcQk74kcspp0q+Wf92ilUGipmBgECSoJiptx8ou8Cso X-Received: by 2002:a17:902:b205:: with SMTP id t5-v6mr1760plr.343.1527022059839; Tue, 22 May 2018 13:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527022059; cv=none; d=google.com; s=arc-20160816; b=KqNApOGD5I241Ia+3Q1w5iv7ub9sLsN2TLAUCbD3NVKv5A6qc86B7fT65+5Eh21f/c FnORcS/7bsfgir1WCzXCDDRn1RRTcjrs3yyn26qIIuobRm0k4CB6vchF4tQQ9HKrQ9NT X5TfIUWFav6pWc3A9kLbQnZ+BLwxuCIUotKd8z3GWLd8F11sli9ucUWMEpY/GOVOsuKb H3MFyiryFTgN5MWHdnYSPwqDQ5nmzqxnZvEJHc825KmG71zc5m90BXcTpWH7e1rzA77z uzu8tR6NCOhYO2c1jCtdq/g4a76xp+ocZ9PGuH21gy6VWsC98OoRo/8l49WuUuBgy4Sl forQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=kzStYTEkbtRCOhI22vZ5fbjCSWXHyvm+LEIVycfUyFE=; b=Rm6dhlPECoh6qbhcmTLf++uDuHM0XLfaUoPuR/sQHzLt9Z9J8yVhsP5p5HIDgfo+0g 8PG0UhS7r4tfKmcy+hSAAfze9Xx7BpDAUuOekDEbphGPVai2/7m+ySCudaRYNb7i4iiR STr+FM8BECr6G/fOLq2ELq6OGXXibcK86TDTY+Fm2J+crufpNQBMnZUyMwvZ0f9Wopez yBa7y6RP1IOQzZR40IdZwPptIkgs9wcE+r5G5JJNsCp1AHQTtRpyw+jvacp7Vz+nUxb3 hfIvzTOQCJEehFao0oLPVUu+aNI//GZPBkDgeiDOp602EOVS20YgqfT0TJHMDsYd2Jso v4Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CHb95dYU; 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 sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l2-v6si7505256pgu.353.2018.05.22.13.47.25; Tue, 22 May 2018 13:47:39 -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=@gmail.com header.s=20161025 header.b=CHb95dYU; 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 sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753066AbeEVUqL (ORCPT + 99 others); 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 Received: by mail-qk0-f195.google.com with SMTP id a8-v6so15729171qkj.12; Tue, 22 May 2018 13:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=kzStYTEkbtRCOhI22vZ5fbjCSWXHyvm+LEIVycfUyFE=; b=CHb95dYUhozBlSST7B4+ku9urRsyqIJaJ/eRAWuZPPNaM3s2ki0XV1dZfm7xew49iR 8BNJMehGgcpAw8cH55fTqrhrpKMRn8gCNiODJGsj2iQxtRQLDJ2TZ0KMqspu0lMbKFId kfV6YVccKLH5Ul9L9Roza1eau/1+nj3hRzsua7/c6oH7SzIEYSgj8LIiqIBtZKquh6y2 rfQP+HAauFsx+LhlYoUtYW8vnHFgp+I7AdMf7CNw7gohWmDhuLFXdh5aJd2Sdxf7z1Pw kaB2geRHnqHlPzIgsONhA7Mc0DrE5vkbW4gn+Z4XlmJsX6sxKn5dJyWXlrvGks5cQZnM 7NZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=kzStYTEkbtRCOhI22vZ5fbjCSWXHyvm+LEIVycfUyFE=; b=pgF7jMLC6pHdQjbPGOrh6atMZlZX/4P6/auOApasgUEE4EEcShdk4DiSXOGoqK9mf8 J0M6vc/vOu3OJReGSOxbjD/c+Dm36mmJ15nptiTUuDN4cRFQMSYQZLuLX2MnWHFMi37m R2v0fa/t8UQ8AuzrhBSkhmzI7yQWbMYbsy0wpmtNxQRVy/msq8Kama6hec1MGpjkCfsd FrpfSI8eAgahC2019aeU70i0T/x0fyvE7/xgMGoRLbsB9Nf5O3KwQeZTS2sU8wX5yWdQ p/JSWXv/3r5rbWTw7Px4Ht/Tlk6s0189b8YXkF56E7MyHqHTtPq4ldXtGUyojFn5wusK vVjA== X-Gm-Message-State: ALKqPwchD0LaDcxD7Ngh2Xt1JIieI+E0Bk3Oj/r1GoyirOM6E+huJKuE Tif/HAKzjEIWRYMltCk0XJvPKvgv/Es3OTtmDRJyHXvjFr4= X-Received: by 2002:a37:1399:: with SMTP id 25-v6mr17254qkt.83.1527021968369; Tue, 22 May 2018 13:46:08 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a0c:9896:0:0:0:0:0 with HTTP; Tue, 22 May 2018 13:46:07 -0700 (PDT) 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 Precedence: bulk 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