Skip to content

Commit 4ea96cf

Browse files
GseoCAlexandre Torgue
authored andcommitted
bus: stm32_firewall: add stm32_firewall_get_grant_all_access() API
Add the stm32_firewall_get_grant_all_access() API to be able to fetch all firewall references in an access-controllers property and try to grant access to all of them. Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> Reviewed-by: Linus Walleij <linusw@kernel.org> Link: https://lore.kernel.org/r/20260226-debug_bus-v6-5-5d794697798d@foss.st.com Signed-off-by: Alexandre Torgue <alexandre.torgue@foss.st.com>
1 parent 892320d commit 4ea96cf

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

drivers/bus/stm32_firewall.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,48 @@ void stm32_firewall_release_access_by_id(struct stm32_firewall *firewall, u32 su
184184
}
185185
EXPORT_SYMBOL_GPL(stm32_firewall_release_access_by_id);
186186

187+
int stm32_firewall_get_grant_all_access(struct device *dev, struct stm32_firewall **firewall,
188+
int *nb_firewall)
189+
{
190+
struct stm32_firewall *loc_firewall;
191+
int err;
192+
int i;
193+
194+
*nb_firewall = of_count_phandle_with_args(dev->of_node, "access-controllers",
195+
"#access-controller-cells");
196+
if (*nb_firewall < 0)
197+
return *nb_firewall;
198+
199+
if (!*nb_firewall) {
200+
*firewall = NULL;
201+
return 0;
202+
}
203+
204+
loc_firewall = devm_kcalloc(dev, *nb_firewall, sizeof(*loc_firewall), GFP_KERNEL);
205+
if (!loc_firewall)
206+
return -ENOMEM;
207+
208+
/* Get stm32 firewall information */
209+
err = stm32_firewall_get_firewall(dev->of_node, loc_firewall, *nb_firewall);
210+
if (err)
211+
return err;
212+
213+
for (i = 0; i < *nb_firewall; i++) {
214+
err = stm32_firewall_grant_access(&loc_firewall[i]);
215+
if (err) {
216+
while (i--)
217+
stm32_firewall_release_access(&loc_firewall[i]);
218+
219+
return err;
220+
}
221+
}
222+
223+
*firewall = loc_firewall;
224+
225+
return 0;
226+
}
227+
EXPORT_SYMBOL_GPL(stm32_firewall_get_grant_all_access);
228+
187229
/* Firewall controller API */
188230

189231
int stm32_firewall_controller_register(struct stm32_firewall_controller *firewall_controller)

include/linux/bus/stm32_firewall_device.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,25 @@ int stm32_firewall_grant_access_by_id(struct stm32_firewall *firewall, u32 subsy
112112
*/
113113
void stm32_firewall_release_access_by_id(struct stm32_firewall *firewall, u32 subsystem_id);
114114

115+
/**
116+
* stm32_firewall_get_grant_all_access - Allocate and get all the firewall(s) associated to given
117+
* device. Then, try to grant access rights for each element.
118+
* This function is basically a helper function that wraps
119+
* both stm32_firewall_get_firewall() and
120+
* stm32_firewall_grant_access() on all firewall references of
121+
* a device along with the allocation of the array.
122+
* Realease access using stm32_firewall_release_access* APIs
123+
* when done.
124+
*
125+
* @dev: Device performing the checks
126+
* @firewall: Pointer to the array of firewall references to be allocated
127+
* @nb_firewall: Number of allocated elements in @firewall
128+
*
129+
* Returns 0 on success, or appropriate errno code if error occurred.
130+
*/
131+
int stm32_firewall_get_grant_all_access(struct device *dev, struct stm32_firewall **firewall,
132+
int *nb_firewall);
133+
115134
#else /* CONFIG_STM32_FIREWALL */
116135

117136
static inline int stm32_firewall_get_firewall(struct device_node *np,
@@ -141,5 +160,12 @@ static inline void stm32_firewall_release_access_by_id(struct stm32_firewall *fi
141160
{
142161
}
143162

163+
static inline int stm32_firewall_get_grant_all_access(struct device *dev,
164+
struct stm32_firewall **firewall,
165+
int *nb_firewall)
166+
{
167+
return -ENODEV;
168+
}
169+
144170
#endif /* CONFIG_STM32_FIREWALL */
145171
#endif /* STM32_FIREWALL_DEVICE_H */

0 commit comments

Comments
 (0)