net/can/j1939/bus.c
Source file repositories/reference/linux-study-clean/net/can/j1939/bus.c
File Facts
- System
- Linux kernel
- Corpus path
net/can/j1939/bus.c- Extension
.c- Size
- 7200 bytes
- Lines
- 337
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
net/sock.hj1939-priv.h
Detected Declarations
function __j1939_ecu_releasefunction j1939_ecu_putfunction j1939_ecu_getfunction j1939_ecu_is_mapped_lockedfunction j1939_ecu_map_lockedfunction j1939_ecu_unmap_lockedfunction j1939_ecu_unmapfunction j1939_ecu_unmap_allfunction j1939_ecu_timer_startfunction j1939_ecu_timer_cancelfunction j1939_ecu_timer_handlerfunction list_for_each_entryfunction j1939_name_to_addrfunction j1939_local_ecu_getfunction j1939_local_ecu_put
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2010-2011 EIA Electronics,
// Kurt Van Dijck <kurt.van.dijck@eia.be>
// Copyright (c) 2017-2019 Pengutronix,
// Marc Kleine-Budde <kernel@pengutronix.de>
// Copyright (c) 2017-2019 Pengutronix,
// Oleksij Rempel <kernel@pengutronix.de>
/* bus for j1939 remote devices
* Since rtnetlink, no real bus is used.
*/
#include <net/sock.h>
#include "j1939-priv.h"
static void __j1939_ecu_release(struct kref *kref)
{
struct j1939_ecu *ecu = container_of(kref, struct j1939_ecu, kref);
struct j1939_priv *priv = ecu->priv;
list_del(&ecu->list);
kfree(ecu);
j1939_priv_put(priv);
}
void j1939_ecu_put(struct j1939_ecu *ecu)
{
kref_put(&ecu->kref, __j1939_ecu_release);
}
static void j1939_ecu_get(struct j1939_ecu *ecu)
{
kref_get(&ecu->kref);
}
static bool j1939_ecu_is_mapped_locked(struct j1939_ecu *ecu)
{
struct j1939_priv *priv = ecu->priv;
lockdep_assert_held(&priv->lock);
return j1939_ecu_find_by_addr_locked(priv, ecu->addr) == ecu;
}
/* ECU device interface */
/* map ECU to a bus address space */
static void j1939_ecu_map_locked(struct j1939_ecu *ecu)
{
struct j1939_priv *priv = ecu->priv;
struct j1939_addr_ent *ent;
lockdep_assert_held(&priv->lock);
if (!j1939_address_is_unicast(ecu->addr))
return;
ent = &priv->ents[ecu->addr];
if (ent->ecu) {
netdev_warn(priv->ndev, "Trying to map already mapped ECU, addr: 0x%02x, name: 0x%016llx. Skip it.\n",
ecu->addr, ecu->name);
return;
}
j1939_ecu_get(ecu);
ent->ecu = ecu;
ent->nusers += ecu->nusers;
}
/* unmap ECU from a bus address space */
void j1939_ecu_unmap_locked(struct j1939_ecu *ecu)
{
struct j1939_priv *priv = ecu->priv;
struct j1939_addr_ent *ent;
lockdep_assert_held(&priv->lock);
if (!j1939_address_is_unicast(ecu->addr))
return;
if (!j1939_ecu_is_mapped_locked(ecu))
return;
ent = &priv->ents[ecu->addr];
ent->ecu = NULL;
ent->nusers -= ecu->nusers;
j1939_ecu_put(ecu);
}
Annotation
- Immediate include surface: `net/sock.h`, `j1939-priv.h`.
- Detected declarations: `function __j1939_ecu_release`, `function j1939_ecu_put`, `function j1939_ecu_get`, `function j1939_ecu_is_mapped_locked`, `function j1939_ecu_map_locked`, `function j1939_ecu_unmap_locked`, `function j1939_ecu_unmap`, `function j1939_ecu_unmap_all`, `function j1939_ecu_timer_start`, `function j1939_ecu_timer_cancel`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.