From mboxrd@z Thu Jan 1 00:00:00 1970 From: Doug Anderson Subject: Re: [PATCH v6 05/10] drivers: qcom: rpmh-rsc: write sleep/wake requests to TCS Date: Fri, 27 Apr 2018 16:24:10 -0700 Message-ID: References: <20180419221635.17849-1-ilina@codeaurora.org> <20180419221635.17849-6-ilina@codeaurora.org> <20180425214111.GC243180@google.com> <20180427173943.GD6380@codeaurora.org> <20180427184017.GI243180@google.com> <20180427194559.GE6380@codeaurora.org> <20180427200605.GJ243180@google.com> <20180427213201.GA23157@codeaurora.org> <20180427215449.GA133494@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: In-Reply-To: <20180427215449.GA133494@google.com> Sender: linux-kernel-owner@vger.kernel.org To: Matthias Kaehlcke Cc: Lina Iyer , Andy Gross , David Brown , linux-arm-msm@vger.kernel.org, "open list:ARM/QUALCOMM SUPPORT" , Rajendra Nayak , Bjorn Andersson , LKML , Stephen Boyd , Evan Green List-Id: linux-arm-msm@vger.kernel.org Hi, On Fri, Apr 27, 2018 at 2:54 PM, Matthias Kaehlcke wrote: >> > Am I getting something wrong here? >> >> The for_each_set_bit() should increment the 'i' and we would attempt to >> compare the first address in the request with the next command in the >> TCS cache. If they don't match we repeat the process again. If it does, >> then we loop through 'j' to find if the sequence matches. >> >> Did I miss something? > > One of us is clearly in need of more caffeine or ready for the > weekend, it might be me :) Maybe another pair of eyeballs could help > to resolve this deadlock ... > > My single stepping above assumes that tcs->cmd_cache[i] matches > cmd[0].addr, i.e. we either found the start of the sequence we are > looking for or another sequence that starts with the same address. My > claim is that the code returns i in either case, whether the > subsequent addresses match or not. I haven't reviewed this patch in detail, but I attempted to be another pair of eyes here. Something is definitely wrong with the "for (j = 0; j < len; j++)" loop. I believe the code that's written right now is equivalent to this much shorter function: +static int find_match(const struct tcs_group *tcs, const struct tcs_cmd *cmd, + int len) +{ + int i, j; + + /* Check for already cached commands */ + for_each_set_bit(i, tcs->slots, MAX_TCS_SLOTS) { + if (tcs->cmd_cache[i] == cmd[0].addr) + return i; + } + + return -ENODATA; +} Specifically the test "if (tcs->cmd_cache[i] != cmd[0].addr)" does not take "j" into account. Thus if it was false when "j == 0" it will continue to be false for "j == 1", "j == 2", etc. Eventually you'll hit the "else if (j == len - 1)" and return. I believe that's what Matthias has been saying. I personally haven't looked at the rest of the patch to see how things out to be fixed, but I'm quite convinced that the function either has a bug or should be written as the shorter version I've written above. -Doug