lkml.org 
[lkml]   [2012]   [Apr]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 09/11] firewire-sbp-target: Add sbp_target_agent.{c,h}
On Apr 11 Chris Boot wrote:
> +static int tgt_agent_rw_agent_state(struct fw_card *card, int tcode, void *data,
> + struct sbp_target_agent *agent)
> +{
> + __be32 state;
> +
> + switch (tcode) {
> + case TCODE_READ_QUADLET_REQUEST:
> + pr_debug("tgt_agent AGENT_STATE READ\n");
> +
> + spin_lock_bh(&agent->lock);
> + state = cpu_to_be32(agent->state);
> + spin_unlock_bh(&agent->lock);
> + memcpy(data, &state, sizeof(state));
> +
> + return RCODE_COMPLETE;
> +
> + case TCODE_WRITE_QUADLET_REQUEST:
> + /* ignored */
> + return RCODE_COMPLETE;
> +
> + default:
> + return RCODE_TYPE_ERROR;
> + }
> +}

agent->state is an int; reading an int is atomic. Hence the access on
its own does not benefit from lock acquisition.

The memcpy can be simplified to

*(__be32 *)data = cpu_to_be32(agent->state);

if data is always at least quadlet aligned. Thy type cast is only to tell
code checkers like sparse that we know what we are doing. If data may be
unaligned, you could use

put_unaligned_be32(agent->state, data);
--
Stefan Richter
-=====-===-- -=-- -===-
http://arcgraph.de/sr/


\
 
 \ /
  Last update: 2012-04-14 12:51    [W:0.212 / U:7.608 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site