title: Specific reasons to use |= instead of =
body: <p>I am currently looking over some code in the Linux kernel (thermal management). In some places there is a return value used to signal errors, which is set to 0 at the beginning of the function. Then when calling a function which may fail it is set to the new value using <code>|=</code> instead of <code>=</code>. Here is an example:</p>
  
  <pre><code>int ti_bandgap_read_temperature(struct ti_bandgap *bgp, int id,
                  int *temperature)
  {
      u32 temp;
      int ret;
  
      ret = ti_bandgap_validate(bgp, id);
      if (ret)
          return ret;
  
      spin_lock(&amp;bgp-&gt;lock);
      temp = ti_bandgap_read_temp(bgp, id);
      spin_unlock(&amp;bgp-&gt;lock);
  
      ret |= ti_bandgap_adc_to_mcelsius(bgp, temp, &amp;temp);
      if (ret)
          return -EIO;
  
      *temperature = temp;
  
      return 0;
  }
  </code></pre>
  
  <p>The definition of <code>ti_bandgap_validate</code> is:</p>
  
  <pre><code>/**
   * ti_bandgap_validate() - helper to check the sanity of a struct ti_bandgap
   * @bgp: struct ti_bandgap pointer
   * @id: bandgap sensor id
   *
   * Checks if the bandgap pointer is valid and if the sensor id is also
   * applicable.
   *
   * Return: 0 if no errors, -EINVAL for invalid @bgp pointer or -ERANGE if
   * @id cannot index @bgp sensors.
   */
  static inline int ti_bandgap_validate(struct ti_bandgap *bgp, int id)
  </code></pre>
  
  <p>So, if my reasoning is correct, at the call to <code>ti_bandgap_adc_to_mcelsius()</code>, the value of <code>ret</code> must be <code>0</code> (otherwise the function would have exited already). So what is the reason for using <code>|=</code> here instead of <code>=</code>? Doing an "or" with a pattern of all zeros will just give back the normal pattern. Is this some kind of optimization for the usual case, i.e. that the function is returning no failure (i.e. return value <code>0</code>)? Or is there some other difference I am missing? This code is running on an ARM-architecture, so it might have to do something with specific optimizations for that platform.</p>